-
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
omit_local_variable_types is not safe with inferred type from generic method #57967
Comments
There is a specific thing that you can do here (which eliminates the need to change the linter): Add explicit type arguments to the generic function calls. main() {
var list2 = createList<int>();
print(list2.runtimeType); // List<int>
var future2 = createFuture<int>();
print(future2.runtimeType); // Future<dynamic>
}
List<T> createList<T>() => [];
Future<T> createFuture<T>() async => null; Those generic functions would typically depend on their context to obtain type arguments, because there are no parameters (and the situation would be similar if some parameter type annotations exist, but they do not mention some of the type parameters). There's "nothing wrong" in giving explicit type arguments to So if the applicable coding standards specify that local variables shouldn't have type annotations then we need to provide this information in some other way. Explicit type arguments on the call is one way to do it. |
Ok, thanks. List<int> list = []; We would lose type information if converted mechanically. That just make me realise that the lint is a bit dangerous and should be enabled cautiously. |
What is the solution for below case:
|
That case should not create any problems: The return type of If the type annotation |
This code with the rule
omit_local_variable_types
The linter emits 2 warnings to remove the local type for
list1
andfuture1
(Omit type annotations for local variables
).However applying the change is not safe because it changes the inferred type and the runtime type.
I think the linter should not report a lint in this case.
The text was updated successfully, but these errors were encountered: