Skip to content

Flow analysis. Assignment is not detected in case ... when ... part #60269

Open
@sgrekhov

Description

@sgrekhov

The following program fails in both CFE and the analyzer.

main() {
  int i;
  if (true case == true when (i = 42) > 0) {
    print("Ok");
  }
  i; // Error: Non-nullable variable 'i' must be assigned before it can be used.
}

Flow analysis for if-case statements is not yet specified in the specification but intuitively I'd expect that it should detect that i is definitely assigned here.

cc @stereotype441

Dart SDK version: 3.8.0-166.0.dev (dev) (Tue Mar 4 20:02:17 2025 -0800) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-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