diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart index 7c2575178be..36768a32a55 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_return_type.dart @@ -18,8 +18,7 @@ class AddReturnType extends ResolvedCorrectionProducer { AddReturnType({required super.context}); @override - CorrectionApplicability get applicability => - CorrectionApplicability.automatically; + CorrectionApplicability get applicability => .automatically; @override AssistKind get assistKind => DartAssistKind.addReturnType; @@ -98,18 +97,18 @@ class AddReturnType extends ResolvedCorrectionProducer { if (body.isGenerator) { return typeProvider.streamElement.instantiate( typeArguments: [baseType], - nullabilitySuffix: baseType.nullabilitySuffix, + nullabilitySuffix: .none, ); } else { return typeProvider.futureElement.instantiate( typeArguments: [baseType], - nullabilitySuffix: baseType.nullabilitySuffix, + nullabilitySuffix: .none, ); } } else if (body.isGenerator) { return typeProvider.iterableElement.instantiate( typeArguments: [baseType], - nullabilitySuffix: baseType.nullabilitySuffix, + nullabilitySuffix: .none, ); } return baseType; diff --git a/pkg/analysis_server/test/src/services/correction/assist/add_return_type_test.dart b/pkg/analysis_server/test/src/services/correction/assist/add_return_type_test.dart index 836ad01190b..0c42a7901df 100644 --- a/pkg/analysis_server/test/src/services/correction/assist/add_return_type_test.dart +++ b/pkg/analysis_server/test/src/services/correction/assist/add_return_type_test.dart @@ -184,6 +184,45 @@ String f() { '''); } + Future test_topLevelFunction_block_async() async { + await resolveTestCode(''' +^f(String? s) async { + return s; +} +'''); + await assertHasAssist(''' +Future f(String? s) async { + return s; +} +'''); + } + + Future test_topLevelFunction_block_asyncStar() async { + await resolveTestCode(''' +^f(String? s) async* { + yield s; +} +'''); + await assertHasAssist(''' +Stream f(String? s) async* { + yield s; +} +'''); + } + + Future test_topLevelFunction_block_syncStar() async { + await resolveTestCode(''' +^f(String? s) sync* { + yield s; +} +'''); + await assertHasAssist(''' +Iterable f(String? s) sync* { + yield s; +} +'''); + } + Future test_topLevelFunction_expression() async { await resolveTestCode(''' ^f() => '';