Skip to content

Inaccurate unnecessary_await_in_return #58001

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

Closed
ThinkDigitalSoftware opened this issue Aug 10, 2019 · 6 comments
Closed

Inaccurate unnecessary_await_in_return #58001

ThinkDigitalSoftware opened this issue Aug 10, 2019 · 6 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@ThinkDigitalSoftware
Copy link

Describe the issue
Linter shows unnecessary_await_in_return if in an expression body, but not when the statement is a block body.

To Reproduce

 onInitialBuild: (store) async {
              await Future.wait(
                  widget.student.guardians.map(
                    (guardian) => guardian.inflate(),
                  ),
                );
            },

No issue here, but when converted to an expression body, it shows a warning.

StoreConnector<AppState, ViewStudentViewModel>(
            onInitialBuild: (store) async => await Future.wait( // warning here.
                  widget.student.guardians.map(
                    (guardian) => guardian.inflate(),
                  ),
                ),

Expected behavior
if it's a simple refactor, then it shouldn't change the correctness of the statement. We should either not offer the refactor, or not show a warning here. I know the fat arrow is short for return, but that's not always desirable nor correct, especially when using void functions.

Screen Shot 2019-08-09 at 5 06 07 PM

Screen Shot 2019-08-09 at 5 06 17 PM

@pq pq added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Aug 10, 2019
@pq
Copy link
Member

pq commented Aug 10, 2019

Good catch. Thanks for the report!

@ThinkDigitalSoftware
Copy link
Author

My pleasure!

@pq
Copy link
Member

pq commented Aug 19, 2019

/cc @a14n

@a14n
Copy link
Contributor

a14n commented Aug 28, 2019

I don't see this as a bug.

In the first snippet there's no return and async/await are needed.

I rather think the refactoring should be changed to have convertions (block/expression) as follow:

Future f() => aFuture;
Future f() async {
  return await aFuture;
}

Future<void> v() => aVoidFuture;
Future<void> v() async {
  await aVoidFuture;
}

@ThinkDigitalSoftware
Copy link
Author

In my case, the callback definition isn't async, but it supports it. Just like onPressed() callbacks. so I can't define that it's a Future. Not sure if that makes a difference

typedef OnInitialBuildCallback<ViewModel> = void Function(ViewModel viewModel)

@srawlins srawlins added the P3 A lower priority bug or feature request label Sep 27, 2022
@srawlins
Copy link
Member

I agree with @a14n; the code in question doesn't have a return statement, so the lint rule does not apply.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. 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

5 participants