Skip to content

Flow analysis. If while part of do-while is Never the code after the loop must be unreachable #60363

@sgrekhov

Description

@sgrekhov

Errors below are not reported either by the analyzer or CFE.

test(Never n) {
  late int i;
  if (1 > 2) {
    do {
    } while (n);
    i = 42;
  }
  i; // Definitely unassigned but no error
}

Another example

test(Never n) {
  late int i;
  if (1 > 2) {
    do {
      i = 42;
    } while (n);
  }
  i; // Definitely unassigned but no error
}

Note that the code below works

test(Never n) {
  late int i;
  if (1 > 2) {
    do {
      i = 42;
      n;
    } while (false);
  }
  i; // Definitely unassigned. Ok, the error the is reported.
}

cc @stereotype441

Dart SDK version: 3.8.0-197.0.dev (dev) (Sat Mar 15 17:07:22 2025 -0700) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-flowImplementation of flow analysis in analyzer/cfe

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions