Skip to content

avoid_annotating_with_dynamic and new typedef #57789

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

Open
dotdoom opened this issue Sep 10, 2018 · 4 comments
Open

avoid_annotating_with_dynamic and new typedef #57789

dotdoom opened this issue Sep 10, 2018 · 4 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@dotdoom
Copy link

dotdoom commented Sep 10, 2018

I'm struggling to make an otherwise useful avoid_annotating_with_dynamic work with my typedef:

typedef CallbackWithParameter = Future<void> Function(dynamic);
// or
typedef CallbackWithParameter = Future<void> Function(dynamic parameter);

both are syntactically valid, but none satisfies this lint check. Templatizing CallbackWithParameter fixes this, but it's not exactly what I'm looking for. Is this check incompatible with the new typedefs?

@bwilkerson
Copy link
Member

Is this check incompatible with the new typedefs?

I don't think so. In both cases you're annotating that the parameter to the function has the type dynamic, which is what the rule is intended to catch. It's possible that this example is one of the places where you'd like to explicitly use dynamic (in which case an 'ignore' comment might be necessary). It's also possible that what you're trying to say is that the parameter is allowed to be any Object. But at this point I'm only guessing at possible solutions.

@dotdoom
Copy link
Author

dotdoom commented Sep 10, 2018

Depending on what the purpose of linter is, an 'ignore' comment may be the right solution. I'm not trying to dispute it though, because I'm new to Dart and even more to the linter.

What I want to say is, contrary to this check description, dynamic is not assumed here by Dart, like e.g. in function parameters, and is required by syntax if the intent is to have a dynamic argument type.

If the purpose of this check is to discourage the use of dynamic, perhaps the description should be rephrased.

@bwilkerson
Copy link
Member

Depending on what the purpose of linter is ...

The purpose of the linter is to help users catch code patterns that, while valid Dart, they would prefer to not have in their code base. Sometimes those patterns are purely a matter of preference, sometimes they help avoid errors in the code.

... contrary to this check description, dynamic is not assumed here by Dart ...

You're right. I now think the rule has a bug in that it fails to allow for the generic function type syntax.

@srawlins
Copy link
Member

I think @dotdoom is correct here. The lint rule says to not type dynamic when a type is implicitly dynamic. We can write:

typedef CallbackWithParameter = Future<void> Function(dynamic);
// or
typedef CallbackWithParameter = Future<void> Function(dynamic parameter);

but we cannot write

typedef CallbackWithParameter = Future<void> Function(parameter);

(unlike in a function-typed parameter), so the the lint should not report this, as there is no implicit dynamic in function types.

@srawlins srawlins added P3 A lower priority bug or feature request linter-false-positive labels Sep 22, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants