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
No hint/warning for mistyped for..in loop variable #18534
Comments
Added this to the 1.4 milestone. |
I like this idea. Kasper had a similar idea of checking that a type is Iterable for for-each statements. Marking Later/ Enhancement/ Hint. Removed this from the 1.4 milestone. |
Unfortunately, the specification says that the for-in statement is equivalent to var n0 = e.iterator; The use of 'var' means that the static type of 'n0.current' is dynamic, which is assignable to 'int'. I have opened issue #18552 to see whether it's possible to change this. |
FWIW, even if the specification is not changed, I think it would still be ok for us to give a hint in this situation. (Just because one construct is syntactic sugar for another, doesn't mean that we have to restrict ourselves to generating hints based on the de-sugared result). |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
This is done now, as of: cb7aa02 |
This code should generate either a hint or a warning (not sure which):
void f(List<String> strings) {
for (int i in strings) {
print(i);
}
}
I would have expected the analyzer to inform me that since the type of strings is List<String>, I can't iterate through it using "int i".
The text was updated successfully, but these errors were encountered: