-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Suppress unnecessary_cast
to Function
when the cast is allowing violation of avoid_dynamic_calls
#56939
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
Summary: The |
A perhaps better option could be to allow |
I think this would be a simple impl, and a good feature. |
I thought I understood this request, but after reading and thinking more, I think I need a lot of clarification 😁
Assuming the answers to the above are yes and yes, should we always allow
So it seems to be a short list of "surrounding expression situations" if we wanted the exception to be conditional. |
Yes.
It should have been a direct call of the function without any I fixed the example in the first comment. See a real world motivating example at https://github.com/dart-lang/test/blob/9e349d0e9f6c477584ea320f7ba2f49f761d84ac/pkgs/matcher/lib/src/core_matchers.dart#L155
It looks like we always allow It is already the case that the It also is just occurring to me now that we already have the option of doing @jakemac53 - how would you feel about using |
Uh oh!
There was an error while loading. Please reload this page.
The pattern for allowing a dynamic call when the
avoid_dynamic_calls
is enabled is to explicitly cast todynamic
orFunction
in the expression that receives the dynamic call. Such a cast should suppress theunnecessary_cast
diagnostic. When we cast toFunction
to allow the dynamic call, we end up with an unnecessary cast.Idiomatic usage of the lint is to keep references as
Object?
throughout as much of the code as possible, and introduce thedynamic
only within the expression where a dynamic call is made. We assume backends will optimize a cast fromObject?
todynamic
. Neitherdynamic
orObject?
is more specific than the other so we lose nothing when we change alldynamic
toObject?
.Function
is more specific thanObject?
, so we would lose information changing allFunction
toObject
orObject?
just to be allowed to cast.I think we should allow specifically casting a
Function
toFunction
whenavoid_dynamic_calls
is enabled.The text was updated successfully, but these errors were encountered: