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 @@ -5335,8 +5335,17 @@ bool ExtraneousReturnFailure::diagnoseAsError() {
5335
5335
if (FD->getResultTypeRepr () == nullptr &&
5336
5336
FD->getParameters ()->getStartLoc ().isValid () &&
5337
5337
!FD->getBaseIdentifier ().empty ()) {
5338
- auto fixItLoc = Lexer::getLocForEndOfToken (
5339
- getASTContext ().SourceMgr , FD->getParameters ()->getEndLoc ());
5338
+ // Insert the fix-it after the parameter list, and after any
5339
+ // effects specifiers.
5340
+ SourceLoc loc = FD->getParameters ()->getEndLoc ();
5341
+ if (auto asyncLoc = FD->getAsyncLoc ())
5342
+ loc = asyncLoc;
5343
+
5344
+ if (auto throwsLoc = FD->getThrowsLoc ())
5345
+ if (throwsLoc.getOpaquePointerValue () > loc.getOpaquePointerValue ())
5346
+ loc = throwsLoc;
5347
+
5348
+ auto fixItLoc = Lexer::getLocForEndOfToken (getASTContext ().SourceMgr , loc);
5340
5349
emitDiagnostic (diag::add_return_type_note)
5341
5350
.fixItInsert (fixItLoc, " -> <#Return Type#>" );
5342
5351
}
Original file line number Diff line number Diff line change @@ -1205,6 +1205,43 @@ func voidFuncWithNestedVoidFunc() {
1205
1205
}
1206
1206
}
1207
1207
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
+
1208
1245
// Special cases: These should not offer a note + fix-it
1209
1246
1210
1247
func voidFuncExplicitType( ) -> Void {
You can’t perform that action at this time.
0 commit comments