Skip to content

Analyzer strong mode allows no strong subtyping #27564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sgrekhov opened this issue Oct 11, 2016 · 2 comments
Closed

Analyzer strong mode allows no strong subtyping #27564

sgrekhov opened this issue Oct 11, 2016 · 2 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

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

@bwilkerson bwilkerson added legacy-area-analyzer Use area-devexp instead. analyzer-strong-mode P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 11, 2016
@sgrekhov sgrekhov changed the title Analyzer strong mode allown no strong subtyping Analyzer strong mode allows no strong subtyping Oct 12, 2016
@leafpetersen
Copy link
Member

This is working as (currently) intended. In the first example, the implied downcast is statically guaranteed to fail based on simple inspection of the initializer, and so we issue an error. In the second example, the mediating interface of the getter leaves open the possibility that the value that reaches the downcast will be an instance of C and so the downcast might succeed. This is an additional strong mode restriction which needs to be specified here: #27530 .

@leafpetersen leafpetersen self-assigned this Oct 13, 2016
@leafpetersen
Copy link
Member

using the implicit-cast:false analyzer option is the current way to opt out of this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants