Skip to content

for-in inference broken in dev.17.0 #31884

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

Closed
natebosch opened this issue Jan 12, 2018 · 3 comments
Closed

for-in inference broken in dev.17.0 #31884

natebosch opened this issue Jan 12, 2018 · 3 comments
Labels
legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@natebosch
Copy link
Member

natebosch commented Jan 12, 2018

When the iterable in a for-in loop needs inference the variable doesn't get the right inferred type. Examples shown with implicit-casts: false, but the broken inference can cause problems in other ways without that option - such as no good feedback in the IDE

An example:

Broken:

void doStuff(int x) {}

void main() {
  var ints = [1];
  for (var x in ints.map((i) => i)) {
    doStuff(x); // The argument type 'dynamic' can't be assigned to the parameter type 'int'.
  }
}

Working if you add a variable so the type is already inferred:

void doStuff(int x) {}

void main() {
  var ints = [1];
  var intermediate = ints.map((i) => i);
  for (var x in intermediate) {
    doStuff(x); // No static error
  }
}

Also works if you force the type of the loop variable

void doStuff(int x) {}

void main() {
  var ints = [1];
  for (int x in ints.map((i) => i)) { // No static error
    doStuff(x);
  }
}

cc @munificent

natebosch added a commit to dart-lang/build that referenced this issue Jan 12, 2018
Work around for dart-lang/sdk#31884 in the
dev.17.0 version of the SDK
natebosch added a commit to dart-lang/build that referenced this issue Jan 12, 2018
Work around for dart-lang/sdk#31884 in the
dev.17.0 version of the SDK
@lrhn
Copy link
Member

lrhn commented Jan 14, 2018

Also, shouldn't the dynamic typed expression be down-cast'able to any type?
(Or is this code analyzed with "no implicit downcasts"?)

@lrhn lrhn added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 14, 2018
@natebosch
Copy link
Member Author

Or is this code analyzed with "no implicit downcasts"?

Yes, we're using implicit-casts: false here

natebosch added a commit to dart-archive/graphs that referenced this issue Jan 16, 2018
Workaround for dart-lang/sdk#31884 in the
dev.17.0 version of the SDK.
natebosch added a commit to dart-archive/graphs that referenced this issue Jan 17, 2018
Workaround for dart-lang/sdk#31884 in the
dev.17.0 version of the SDK.
@leafpetersen
Copy link
Member

Seems to be fixed in dev.18

dcharkes pushed a commit to dart-lang/tools that referenced this issue May 23, 2023
Workaround for dart-lang/sdk#31884 in the
dev.17.0 version of the SDK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants