Skip to content

Flow analysis unnecessarily demotes for-each loop variables #42653

@stereotype441

Description

@stereotype441

The following code is currently rejected by flow analysis:

void forEachWithoutDeclLoopVar(Object x) {
  if (x is int) {
    x.isEven; // Verify that promotion occurred
    for (x in [0]) {
      x.isEven; // ERROR: `Object` has no method `isEven`
      break;
    }
  }
}

It seems like we should be able to do better than this, because [0] should be inferred as <int>[0], and therefore the implicit assignment to x in the for-each loop should not undo the promotion.

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.type-enhancementA request for a change that isn't a bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions