Skip to content

No warning in case of variable assignment before the first type test #59614

@sgrekhov

Description

@sgrekhov
class C {}
class D {}

main() {
  Object o = C();
  if (o is C) {} // No warning
  o = C();
  if (o is C) {} // unnecessary_type_check warning.
  o = D();
  if (o is D) {} // No warning
  if (o is D) {} // No warning
  o = D();
  if (o is D) {} // unnecessary_type_check warning.
}

Why there is no warning after the first assignment of the new object instance?

Dart SDK version: 3.7.0-183.0.dev (dev) (Fri Nov 22 20:03:46 2024 -0800) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).type-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