Use Future<void> when extract an async method that returns nothing.

R=brianwilkerson@google.com

Change-Id: Ic148974ba587310c475795caf8ed0c8565d96909
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182664
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-02-03 22:25:39 +00:00 committed by commit-bot@chromium.org
parent 43e4536ebb
commit 3be5f7c356
3 changed files with 7 additions and 2 deletions

View file

@ -861,6 +861,10 @@ class CorrectionUtils {
}
}
if (type is VoidType) {
return 'void';
}
throw StateError('(${type.runtimeType}) $type');
}

View file

@ -762,7 +762,8 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
} else if (_returnType == null) {
variableType = null;
if (_hasAwait) {
returnType = _getTypeCode(typeProvider.futureDynamicType);
var futureVoid = typeProvider.futureType2(typeProvider.voidType);
returnType = _getTypeCode(futureVoid);
} else {
returnType = 'void';
}

View file

@ -2431,7 +2431,7 @@ main() async {
// end
}
Future<dynamic> res() async {
Future<void> res() async {
int v = await getValue();
print(v);
}