-
Notifications
You must be signed in to change notification settings - Fork 1.7k
strong_mode_implicit_dynamic_method ignores @optionalTypeArgs #32538
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
Comments
The error appears to be generated in (And the annotation is mis-documented as only being applicable to class declarations, when it really ought to be applicable to any declaration that can have type parameters.) |
If there's any chance this could be fixed sooner rather than later that would be awesome. I have a PR where I add some type arguments to some commonly used methods and I am really trying to get the inference to help me at analysis time rather than requiring people to type in the types... right now I have 158 instances of this error in the Flutter repo all of which I'd like to silence by specifying |
cc @jmesserly A workaround is to declare the generic method parameter with a bound of |
That workaround is sufficient, thanks. |
As @leafpetersen mentioned, an optional type arg can be declared with class A {
void test<T extends Object>() { }
}
void main() {
new A().test();
} The nice thing about that is it prevents dynamic from being implicitly used. Helps for examples like: class A {
List<T> test<T>() => <T>[];
}
void main() {
var list = new A().test(); // implicit List<dynamic>
list.add('a string!');
list.first.methodThatDoesNotExist();
} That produces a runtime error. If changed to Also FWIW, request for optionalTypeArgs to be recognized was also reported in: #26901 |
aside: it might be nice if we had an option for instantiate-to-bounds to choose |
YES THIS PLEASE. |
Yeah, I've wondered whether --no-implicit-dynamic shouldn't just do that. I tested out using Object globally instead of dynamic, and unfortunately it's fairly breaking. |
I don't think a linter flag should change program semantics. I don't want multiple incompatible semantics to be implemented and used by different users. If we change the implicit bound to |
Yeah, it would be way too much to all fix at once. If we did want to investigate a change to the default bound, a flag could come in handy. It gives us a way to see if we can move some pieces of code to the new rules, and whether we like the result. If it seems like a good change, then it can be rolled out incrementally across the codebase by opting in, then eventually we can eliminate the flag. (Strong-mode flag was prototyped, and eventually rolled out using a similar approach.) |
|
->
The text was updated successfully, but these errors were encountered: