Skip to content

avoid_types_on_closure_parameters false positive with implicit-dynamic #58695

Closed
@rrousselGit

Description

@rrousselGit

Describe the issue
Some SDK functions type their error callback parameter as Function to accept both Function(Object) and Function(Object, StackTrace):

Future future;
future.then(..., onError: <this callback>);

As such, writing the following will trigger implicit-dynamic:

Future future;
future.then(..., onError: (err, stack) {
  // err and stack are both dynamic
});

The solution should be to explicitly write the type:

Future future;
future.then(..., onError: (Object err, StackTrace stack) {
  // fixed implicit-dynamic
});

but doing this now causes avoid_types_on_closure_parameters on both parameters

Expected 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

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestdevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-positivetype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions