Skip to content
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 #59229

Closed
wujek-srujek opened this issue Jul 25, 2023 · 1 comment
Closed

avoid_types_on_closure_parameters false positive #59229

wujek-srujek opened this issue Jul 25, 2023 · 1 comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@wujek-srujek
Copy link

wujek-srujek commented Jul 25, 2023

https://dart.dev/tools/linter-rules/avoid_types_on_closure_parameters has false positives. Consider the following analysis_options.yaml:

analyzer:
  language:
    strict-casts: true
    strict-inference: true
    strict-raw-types: true

linter:
  rules:
    - avoid_types_on_closure_parameters

The following code:

void main() {
  final closure = (s) { doSomething(s); };
}

void doSomething(String s) {}

triggers the error:

The argument type 'dynamic' can't be assigned to the parameter type 'String'.

When I change the code so that there is no error:

void main() {
  final closure = (String s) { doSomething(s); }; // <= Type annotation in closure added.
}

void doSomething(String s) {}

it triggers the lint, and seemingly the only way to get rid of it is to add an ignore.

Would it be possible for the lint to be triggered only when the type is not necessary, but when it is, the lint should not be triggered?

@srawlins
Copy link
Member

Looks like a duplicate of #57756.

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

3 participants