Skip to content

Flow analysis. Promotion in try-catch statement issue #60519

@sgrekhov

Description

@sgrekhov

@stereotype441, please help me to figure out if the below is an issue or an expected behavior? Shouldn't s be promoted to T in this case?

class S {}

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

main() {
  S s = S();
  try {
    if (s is T) {} // make `T` a type of interest
  } on Exception catch (_) {
    s = T();
    s.answer(); // Error. The method 'answer' isn't defined for the type 'S'
  }
}

Dart SDK version: 3.8.0-278.0.dev (dev) (Mon Apr 7 17:08:37 2025 -0700) on "windows_x64"

Metadata

Metadata

Assignees

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