Skip to content

Flow analysis. Type of interest and the for loop increment part #60557

Closed as not planned
@sgrekhov

Description

@sgrekhov

@stereotype441 is the following expected? Why if type T is made a type of interest in the increment part of the for(;;) loop then a variable of type S cannot be promoted to T in the body of the loop but can be after it?

class S {}

class T extends S {
  int answer() => 42;
}

test1() {
  S s = S();
  for (int i = 0; i < 1; s is T ? true : false, i++) {
    s = T();
    s.answer(); // Error. The method 'answer' isn't defined for the type 'S'. 
  }
}

test2() {
  S s = S();
  for (int i = 0; i < 1; s is T ? true : false, i++) {
  }
  s = T();
  s.answer(); // Ok
}

Dart SDK version: 3.9.0-23.0.dev (dev) (Tue Apr 15 21:06:42 2025 -0700) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    model-flowImplementation of flow analysis in analyzer/cfetype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions