Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for more type checking in the for-in statement #18552

Closed
bwilkerson opened this issue Apr 30, 2014 · 3 comments
Closed

Allow for more type checking in the for-in statement #18552

bwilkerson opened this issue Apr 30, 2014 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@bwilkerson
Copy link
Member

If the definition of the for-in statement were re-written to be


T n0 = e.iterator;
while (n0.moveNext()) {
   finalConstVarOrType? id = n0.current;
   s
}

where 'T' is the static type of 'e.iterator'.


We would be able to detect when the type of 'n0.current' is not assignable to 'id'. See issue #18534 for background.

@lrhn
Copy link
Member

lrhn commented Apr 30, 2014

This would not require e to implement Iterable, it can still be anything that has an "iterator" getter.
However, if the static type of e happens to be "Iterable<SomeType>", then the static type of "e.iterator" would be "Iterator<SomeType>", and using that as the type of "iterator" would man that "iterator.current" has static type "SomeType" - and we would be able to warn instead of just hinting.

@bwilkerson bwilkerson added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Apr 30, 2014
@sigurdm
Copy link
Contributor

sigurdm commented Sep 14, 2015

Any news on this?
Is the spec not allowed to be changed in a way that gives more warnings, but same unchecked behavior?
I think many people stumble on this, and think this has to do with the unsoundness of dart's type system (and not just a problem in the specification).

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@munificent
Copy link
Member

We do this now: #18534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants