-
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 has spurious diagnostics when the variable type impacts inference #59317
Comments
Sigh, yeah I think we have to file this in the bucket of "in order to implement this perfectly correctly, the lint rule needs to run during inference" (or at least have knowledge of context types). |
To be perfectly correct, right, lint needs to be able to re-run inference for the expression without a context type. But to just exclude false positives, we could simple modify the check from "is a type variable" to "contains a type variable". This is a conservative check, so there will be false negatives. But at least it will be more consistent than it is now, since now we can get both false negatives and false positives. |
For what it's worth, I'm not convinced that even that would be enough. I think it's the case that we would need to be able to ask "what if" questions. Things like "what would the (inferred) type of this variable be if we were to remove the type annotation. Yes, that requires running inference over the modified code, but I don't think we'd be able to answer that question while running inference over the unmodified code. |
I think this is very pragmatic! 👍
Oh I think you're right. Yeah this might need to include flow analysis of statements and expressions that follow the variable declaration, with a "hypothetical" type. This is the same conundrum as the |
@pq as a P1, this ticket should be actively worked on. Is this one you are planning to take, or should I assign to someone else? |
Agreed. I'm not actively on this one so if anyone is game, they're welcome to jump on it! |
There is a way to simplify the "false positives are complex" issue with |
@stereotype441: more fodder for the flow analysis conversation |
The lint fires and asks for the local variable type to be removed, but doing so changes the static type of the variable. We don't correctly check when the variable impacts inference, because we only check whether the return type is a type variable.
sdk/pkg/linter/lib/src/rules/omit_local_variable_types.dart
Line 132 in 6885e82
Once the type is more complicated, like
Future<T>
, the lint misfires.cc @pq @yanok
The text was updated successfully, but these errors were encountered: