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

No hint/warning for mistyped for..in loop variable #18534

Closed
stereotype441 opened this issue Apr 29, 2014 · 7 comments
Closed

No hint/warning for mistyped for..in loop variable #18534

stereotype441 opened this issue Apr 29, 2014 · 7 comments
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@stereotype441
Copy link
Member

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".

@bwilkerson
Copy link
Member

Added this to the 1.4 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium label.

@jwren
Copy link
Member

jwren commented Apr 30, 2014

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.
Added this to the Later milestone.
Removed Type-Defect label.
Added Type-Enhancement, Analyzer-Hint labels.

@bwilkerson
Copy link
Member

Unfortunately, the specification says that the for-in statement is equivalent to

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

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.

@stereotype441
Copy link
Member Author

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).

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@stereotype441 stereotype441 added Type-Enhancement area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
@munificent
Copy link
Member

This is done now, as of: cb7aa02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants