Skip to content

Analyzer strong mode allows no strong subtyping #27564

Closed
@sgrekhov

Description

@sgrekhov

Look at the following example of the code:

class A {}

class C extends A {}

void main() {
  C c = new A();
}

In a strong mode analyzer produces an error "[error] Type check failed: new A() (A) is not of type C" and this is an expected result. You can't assign A to type C. But let's rewrite the example above in the following way:

class A {}

class C extends A {
  A get a => new A();
}
void main() {
  C c = new C().a;
}

Instance of A assigned to variable of type C and analyzer (1.19.1 and 1.20.0-dev.10.2) finds no issues here. There should be an error as well

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions