dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.18k stars 1.57k forks source link

Extracting `void` asyncrhonous functions should cast `Future<void>` #56853

Open FMorschel opened 2 days ago

FMorschel commented 2 days ago

The "Extract function" option for the following code:

void g(void Function() s) {}

void bar() {
  g(() async {
    print('some code here');
  });
}

Extracts a new function correctly, but in cases like the above, we have a void return with an async function. I propose that in these cases we change the return type for Future<void>.

Current output:

void newFn() async {
  print('some code here');
}

Proposal:

Future<void> newFn() async {
  print('some code here');
}
dart-github-bot commented 2 days ago

Summary: The "Extract function" refactoring incorrectly extracts void asynchronous functions as void instead of Future<void>. The proposed fix is to change the extracted function's return type to Future<void> for consistency with asynchronous behavior.

FMorschel commented 2 days ago

Related to: