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_void_async not working as expected #3170

Open
zim32 opened this issue Jan 20, 2022 · 5 comments
Open

avoid_void_async not working as expected #3170

zim32 opened this issue Jan 20, 2022 · 5 comments
Labels
lint-request P3 A lower priority bug or feature request set-none Does not affect any rules in a defined rule set (e.g., core, recommended, flutter) type-enhancement A request for a change that isn't a bug

Comments

@zim32
Copy link

zim32 commented Jan 20, 2022

Describe the issue
I had a hard to detect bug, where avoid_void_async could help a lot but it did not

Here is code to reproduce:

class Test {
  void Function() callback;
  Test({required this.callback});
}

Future<void> main(List<String> arguments) async {
  Test(
    callback: () async {},
  );
}

Here I expect that I can not type async in callback parameter, because it expects void Function() instead of Future Fucntion()

This is intented behaviour or a bug?

Here is my linter rules:

linter:
  rules:
    - unawaited_futures
    - await_only_futures
    - avoid_void_async
    - void_checks
@parren-google
Copy link

Seems similar to #1123.

@srawlins srawlins added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) false-negative labels Jun 29, 2022
@bwilkerson bwilkerson added set-none Does not affect any rules in a defined rule set (e.g., core, recommended, flutter) P4 labels Nov 7, 2022
@srawlins
Copy link
Member

This is not the purview of avoid_void_async. A function which is typed void Function() can be async. That lint rule discourages you from writing a return type of void for a function which is async.

I think your issue is valid though, if void-typed async functions are to be avoided. It sounds like it would warrant a new rule, that discourages you from using an async function in a context of a Future-returning function type.

@srawlins srawlins added type-enhancement A request for a change that isn't a bug lint-request P3 A lower priority bug or feature request and removed type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) false-negative P4 labels Apr 17, 2024
@eernstg
Copy link
Member

eernstg commented Apr 19, 2024

Note that this issue has some amount of overlap with dart-lang/language#3715, which is reporting that the inferred return type for sync*, async, and async* function literals differs from the specified value.

In particular, () async {} in the example should have an inferred return type of void because it occurs in a position where the context type is void Function(). However, it is actually inferred to have return type Future<void>.

If the static analysis is adjusted such that the inferred return type is void then the function literal should be flagged by avoid_void_async because it's a function whose body has the modifier async, and it has declared return type void.

@bwilkerson
Copy link
Member

@scheglov For the presumed inconsistency with the specification in the second paragraph above. (Assuming that "should have" means according to the spec.)

@eernstg
Copy link
Member

eernstg commented Apr 19, 2024

Oh, I did mean "according to the spec", but the outcome of the discussion in dart-lang/language#3715 could still be "we don't like breaking changes, so let's change the specification to match the current behavior".

Also, if the rest of the language team supports changing the behavior to be like the specified behavior then there might have to be a breaking change process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint-request P3 A lower priority bug or feature request set-none Does not affect any rules in a defined rule set (e.g., core, recommended, flutter) type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants