-
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
avoid_types_on_closure_parameters false positive with implicit-dynamic #58695
Comments
I think this would be a special case we'd have to hard-code into the linter. The type of that callback is I believe special casing in this lint rule would be a prudent, practical, beneficial policy. |
Assuming the special casing is based on Because ultimately folks may write utilities around such as: void doSomething(Function fn) {
Stream().handleError(fn);
}
// will warn
doSomething((Object err, StackTrace stack) {
}); |
In my opinion the issue is more general and arises at several places (assignments, arguments, declarations...) where a dynamic f1;
f1 = (int a) {}; // LINT
Function f2;
f2 = (int a) {}; // LINT
Object f3;
f3 = (int a) {}; // LINT
var l = [
(int a) => 1, // LINT
]; |
this is quite a pain point for me, because I do want the lint to prevent me and my colleagues from putting type annotations on closures wherever possible, but I also don't want to have to pepper the code with // ignore: comments whereever I use provider's SelectContext.select method: https://pub.dev/documentation/provider/latest/provider/SelectContext/select.html context.select((SomeModel m) => m.attr), //LINT |
Fixes https://github.com/dart-lang/linter/issues/1099 Fixes https://github.com/dart-lang/linter/issues/3330 We just add a check that the (approximate) context type is a function type. Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I56fe14ff8852375754fdaf6b92b3c632b7df9c95 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367982 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
Fixed with f07e042 |
Describe the issue
Some SDK functions type their error callback parameter as
Function
to accept bothFunction(Object)
andFunction(Object, StackTrace)
:As such, writing the following will trigger implicit-dynamic:
The solution should be to explicitly write the type:
but doing this now causes
avoid_types_on_closure_parameters
on both parametersExpected behavior
I would expect avoid_types_on_closure_parameters to detect that Object/StackTrace are types more specific than
dynamic
, and therefore allow it.Additional context
Possibly related to #57586 and #58183
The text was updated successfully, but these errors were encountered: