-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Analyzer doesn't infer type from "is" check against abstract class #26576
Comments
It doesn't actually have anything to do with the fact that
But |
So why in the code snippet above |
Because of the difference between analysis-time (equivalent to compile-time) and run-time semantics. When we're performing a static analysis of the code we don't try to do full flow analysis. You told us that |
Thanks. Is it a correct way to suppress such analyzer warnings? if (a1 is I) (a1 as Object/*=I*/).foo(); |
Nope. Try putting that into DartPad; you'll see two errors rather than one. There are three ways to disable the warning. The best is to add an explicit cast to the tested for type:
The other two involve telling analyzer not to type check your code (which I don't recommend). One is to replace the line with the warning with:
The other is to change the declaration to:
|
DartPad and IntelliJ don't give any errors with strong mode enabled. Ctrl-click on |
Correct. That's because, with strong mode enabled, the code is effectively rewritten to
Without strong mode the content of the comment is ignored. But there's no reason to make the code valid only when strong mode is enabled :-) |
Analyzer doesn't infer type from
is
check against abstract class if variable was annotated with explicit type.https://dartpad.dartlang.org/c6d0fee76a4986d8be05e1288d288e1c
The text was updated successfully, but these errors were encountered: