-
Notifications
You must be signed in to change notification settings - Fork 170
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
unnecessary_lambdas
constructor tear-off false postitives
#4914
Comments
This is correct behavior, so the issue is with recommending using the tear-offs. The error is correct. The torn off constructor cannot take any value as argument, so it cannot be used as a function with Wrapping in So the analyzer may want to check that the parameter type and argument expression types are actually compatible with the tear-off before recommending it. |
Good catch! It looks like [].map((e) => A(e));
[].map((e) => A.new(e)); and that we should fix these false positives in the linter. Thanks for the report @MohiuddinM! |
unnecessary_lambdas
constructor tear-off false postitives
Interestingly, we have several design forces pushing each other around here.
However, some other lint or option (perhaps That should help nudging developers in the direction of the more concise and statically typed variant Still, For the future, if and when we get dart-lang/language#3527, we will also be able to infer |
Basically, in `_visitInstanceCreation`, we make sure that, given an expression like `(e) => C(e))`, that the function type of the outer function expression is the same as the function type of `C(e)`. And little cleanups: * _extractElementsOfSimpleIdentifiers's returned Iterable is only used to check whether it contains something, so change it to a Set. * In `isFinalNode`, use `unParenthesized` to unwrap parens, rather calling recursively. * In `_Visitor`, we stored a `LinterContext`, but we only need the TypeSystem object, so just store that for more terse code later. * In `_visitInstanceCreation`, remove the local function, `matches`, by checking whether all arguments are SimpleIdentifiers. * Convert `isFinalElement` to an extension getter on `Expression`. * Remove helper `isTearoffAssignable`. It is more concise and I think easier to read to just use TypeSystem.isSubtypeOf on its own. * When looking at a VariableDeclaration, get the type from the declared element, which will include inference, rather than the literal type annotation on the declaration. Fixes dart-lang/linter#4914 Fixes dart-lang/linter#3516 Change-Id: I3e89ee4dc011473511d375b0ad324988232c8c96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364628 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
Fixed with dart-lang/sdk@293469e |
The text was updated successfully, but these errors were encountered: