Skip to content

Flow analysis. Patterns match in switches #60677

Closed as not planned
Closed as not planned
@sgrekhov

Description

@sgrekhov

The code below doesn't produce expected error in either CFE and the analyzer.

void test1() {
  late int i;
  switch (42) {
    case String _: // Warning: The matched value type 'int' can never match the required type 'String'. Try using a different pattern. • pattern_never_matches_value_type
      i = 42;
    default:
  }
  i; // Definitely unassigned
//^
// [analyzer] unspecified
// [cfe] unspecified
}

Flow analysis for patterns is not specified yet, but intuitively I'd expect an error here.

cc @stereotype441

Dart SDK version: 3.9.0-95.0.dev (dev) (Sun May 4 21:03:05 2025 -0700) 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