File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -5341,8 +5341,17 @@ bool ExtraneousReturnFailure::diagnoseAsError() {
53415341 if (FD->getResultTypeRepr () == nullptr &&
53425342 FD->getParameters ()->getStartLoc ().isValid () &&
53435343 !FD->getBaseIdentifier ().empty ()) {
5344- auto fixItLoc = Lexer::getLocForEndOfToken (
5345- getASTContext ().SourceMgr , FD->getParameters ()->getEndLoc ());
5344+ // Insert the fix-it after the parameter list, and after any
5345+ // effects specifiers.
5346+ SourceLoc loc = FD->getParameters ()->getEndLoc ();
5347+ if (auto asyncLoc = FD->getAsyncLoc ())
5348+ loc = asyncLoc;
5349+
5350+ if (auto throwsLoc = FD->getThrowsLoc ())
5351+ if (throwsLoc.getOpaquePointerValue () > loc.getOpaquePointerValue ())
5352+ loc = throwsLoc;
5353+
5354+ auto fixItLoc = Lexer::getLocForEndOfToken (getASTContext ().SourceMgr , loc);
53465355 emitDiagnostic (diag::add_return_type_note)
53475356 .fixItInsert (fixItLoc, " -> <#Return Type#>" );
53485357 }
Original file line number Diff line number Diff line change @@ -1205,6 +1205,43 @@ func voidFuncWithNestedVoidFunc() {
12051205 }
12061206}
12071207
1208+ func voidFuncWithEffects1( ) throws {
1209+ return 1
1210+ // expected-error@-1 {{unexpected non-void return value in void function}}
1211+ // expected-note@-2 {{did you mean to add a return type?}}{{35-35= -> <#Return Type#>}}
1212+ }
1213+
1214+ func voidFuncWithEffects2( ) async throws {
1215+ return 1
1216+ // expected-error@-1 {{unexpected non-void return value in void function}}
1217+ // expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
1218+ }
1219+
1220+ // expected-error@+1 {{'async' must precede 'throws'}}
1221+ func voidFuncWithEffects3( ) throws async {
1222+ return 1
1223+ // expected-error@-1 {{unexpected non-void return value in void function}}
1224+ // expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
1225+ }
1226+
1227+ func voidFuncWithEffects4( ) async {
1228+ return 1
1229+ // expected-error@-1 {{unexpected non-void return value in void function}}
1230+ // expected-note@-2 {{did you mean to add a return type?}}{{34-34= -> <#Return Type#>}}
1231+ }
1232+
1233+ func voidFuncWithEffects5( _ closure: ( ) throws -> Void ) rethrows {
1234+ return 1
1235+ // expected-error@-1 {{unexpected non-void return value in void function}}
1236+ // expected-note@-2 {{did you mean to add a return type?}}{{65-65= -> <#Return Type#>}}
1237+ }
1238+
1239+ func voidGenericFuncWithEffects< T> ( arg: T ) async where T: CustomStringConvertible {
1240+ return 1
1241+ // expected-error@-1 {{unexpected non-void return value in void function}}
1242+ // expected-note@-2 {{did you mean to add a return type?}}{{49-49= -> <#Return Type#>}}
1243+ }
1244+
12081245// Special cases: These should not offer a note + fix-it
12091246
12101247func voidFuncExplicitType( ) -> Void {
You can’t perform that action at this time.
0 commit comments