Suggest functions returning void as tearoffs where a void returning function is expected
Closes: https://github.com/dart-lang/sdk/issues/23984
Change-Id: I8291687d962a5d2885e5fa811167ca7e12aedc1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201286
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart b/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart
index f1a747c..03aca89 100644
--- a/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart
+++ b/pkg/analysis_server/test/src/services/completion/dart/completion_test.dart
@@ -9,6 +9,7 @@
void main() {
defineReflectiveSuite(() {
+ defineReflectiveTests(ArgumentListCompletionTest);
defineReflectiveTests(ConstructorCompletionTest);
defineReflectiveTests(ExtensionCompletionTest);
defineReflectiveTests(PropertyAccessorCompletionTest);
@@ -16,6 +17,25 @@
}
@reflectiveTest
+class ArgumentListCompletionTest extends CompletionTestCase {
+ Future<void> test_functionWithVoidReturnType() async {
+ addTestFile('''
+void f(C c) {
+ c.m(^);
+}
+
+void g() {}
+
+class C {
+ void m(void Function() handler) {}
+}
+''');
+ await getSuggestions();
+ assertHasCompletion('g');
+ }
+}
+
+@reflectiveTest
class ConstructorCompletionTest extends CompletionTestCase {
Future<void> test_constructor_abstract() async {
addTestFile('''
diff --git a/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart b/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart
index 394b784..ef103f2c 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/completion/optype.dart
@@ -308,6 +308,10 @@
}
if (0 <= index && index < parameters.length) {
var param = parameters[index];
+ var paramType = param.type;
+ if (paramType is FunctionType && paramType.returnType.isVoid) {
+ optype.includeVoidReturnSuggestions = true;
+ }
if (param.isNamed == true) {
var context = _argumentListContext(node);
optype.completionLocation = 'ArgumentList_${context}_named';