-
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
Warn when implicitly using 'dynamic' #24712
Comments
Do you ever do this in Flutter? |
Yes, a lot. Usually in the form: class Foo<T> {
bool bar(dynamic x) => x is T;
}
// ...
... new Foo<List<String>>() ... ...or whatever. The easiest-to-explain example of this is the drag-and-drop system, where you say what kind of data type you'll want to receive. It only works if anywhere that you add data to the drag system, you do it in a fully-typed way, otherwise everything will be recognised as a match even if it isn't. (The other thing we do all the time is compare runtimeTypes of specialised types. That one happens even more. For example, we might compare a |
We've discussed this for strong mode. Related issues here: dart-archive/dev_compiler#363 For your purposes, I think you'd want us to turn off inference of type arguments (or at least provide you with feedback that we have done such inference) since you are running on the VM and hence the inferred types would not actually be reified as such at runtime. |
FYI - I'm addressing these sort of issues now. Splitting this off into a few specific features that we've identified: #26583 -- flag for disabling implicit casts Let me know if there's more that isn't captured here. We think those flags will go a long way towards "stronger" Dart. Especially no-implicit-dynamic, which catches all kinds of things (dynamic dispatch + dynamic ending up in generic methods/classes). |
I'd love to see a way to enable warnings from the analyzer in the following cases:
runtimeType
var
.(Explicit use of
dynamic
is fine, there's times where it's just what you need.)The text was updated successfully, but these errors were encountered: