@@ -127,7 +127,9 @@ protocol Shoes {
127
127
128
128
// Here the opaque value has type (metatype_type (archetype_type ... ))
129
129
func f( _ x: Shoes , asType t: Shoes . Type ) {
130
- return t. select ( x) // expected-error{{unexpected non-void return value in void function}}
130
+ return t. select ( x)
131
+ // expected-error@-1 {{unexpected non-void return value in void function}}
132
+ // expected-note@-2 {{did you mean to add a return type?}}
131
133
}
132
134
133
135
precedencegroup Starry {
@@ -184,7 +186,9 @@ func perform<T>() {} // expected-error {{generic parameter 'T' is not used in f
184
186
185
187
// <rdar://problem/17080659> Error Message QOI - wrong return type in an overload
186
188
func recArea( _ h: Int , w : Int ) {
187
- return h * w // expected-error {{unexpected non-void return value in void function}}
189
+ return h * w
190
+ // expected-error@-1 {{unexpected non-void return value in void function}}
191
+ // expected-note@-2 {{did you mean to add a return type?}}
188
192
}
189
193
190
194
// <rdar://problem/17224804> QoI: Error In Ternary Condition is Wrong
@@ -752,7 +756,9 @@ func segfault23433271(_ a : UnsafeMutableRawPointer) {
752
756
// <rdar://problem/23272739> Poor diagnostic due to contextual constraint
753
757
func r23272739( _ contentType: String ) {
754
758
let actualAcceptableContentTypes : Set < String > = [ ]
755
- return actualAcceptableContentTypes. contains ( contentType) // expected-error {{unexpected non-void return value in void function}}
759
+ return actualAcceptableContentTypes. contains ( contentType)
760
+ // expected-error@-1 {{unexpected non-void return value in void function}}
761
+ // expected-note@-2 {{did you mean to add a return type?}}
756
762
}
757
763
758
764
// <rdar://problem/23641896> QoI: Strings in Swift cannot be indexed directly with integer offsets
@@ -863,8 +869,8 @@ class Foo23752537 {
863
869
extension Foo23752537 {
864
870
func isEquivalent( other: Foo23752537 ) {
865
871
// TODO: <rdar://problem/27391581> QoI: Nonsensical "binary operator '&&' cannot be applied to two 'Bool' operands"
866
- // expected-error @+1 {{unexpected non-void return value in void function}}
867
- return ( self . title != other. title && self . message != other. message)
872
+ // expected-error@+1 {{unexpected non-void return value in void function}}
873
+ return ( self . title != other. title && self . message != other. message) // expected-note {{did you mean to add a return type?}}
868
874
}
869
875
}
870
876
@@ -890,7 +896,9 @@ func f23213302() {
890
896
891
897
// <rdar://problem/24202058> QoI: Return of call to overloaded function in void-return context
892
898
func rdar24202058( a : Int ) {
893
- return a <= 480 // expected-error {{unexpected non-void return value in void function}}
899
+ return a <= 480
900
+ // expected-error@-1 {{unexpected non-void return value in void function}}
901
+ // expected-note@-2 {{did you mean to add a return type?}}
894
902
}
895
903
896
904
// SR-1752: Warning about unused result with ternary operator
@@ -953,7 +961,9 @@ r27212391(a: 1, 3, x: 5) // expected-error {{argument 'x' must precede unname
953
961
954
962
// SR-1255
955
963
func foo1255_1( ) {
956
- return true || false // expected-error {{unexpected non-void return value in void function}}
964
+ return true || false
965
+ // expected-error@-1 {{unexpected non-void return value in void function}}
966
+ // expected-note@-2 {{did you mean to add a return type?}}
957
967
}
958
968
func foo1255_2( ) -> Int {
959
969
return true || false // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
@@ -1150,6 +1160,7 @@ func sr5045() {
1150
1160
let doubles : [ Double ] = [ 1 , 2 , 3 ]
1151
1161
return doubles. reduce ( 0 , + )
1152
1162
// expected-error@-1 {{unexpected non-void return value in void function}}
1163
+ // expected-note@-2 {{did you mean to add a return type?}}
1153
1164
}
1154
1165
1155
1166
// rdar://problem/32934129 - QoI: misleading diagnostic
@@ -1165,7 +1176,9 @@ class L_32934129<T : Comparable> {
1165
1176
1166
1177
func length( ) -> Int {
1167
1178
func inner( _ list: L_32934129 < T > ? , _ count: Int ) {
1168
- guard let list = list else { return count } // expected-error {{unexpected non-void return value in void function}}
1179
+ guard let list = list else { return count }
1180
+ // expected-error@-1 {{unexpected non-void return value in void function}}
1181
+ // expected-note@-2 {{did you mean to add a return type?}}
1169
1182
return inner ( list. next, count + 1 )
1170
1183
}
1171
1184
@@ -1315,3 +1328,60 @@ takesGenericFunction(true) // expected-error {{cannot convert value of type 'Boo
1315
1328
func takesTuple< T> ( _ x: ( [ T ] , [ T ] ) ) { } // expected-note {{in call to function 'takesTuple'}}
1316
1329
takesTuple ( true ) // expected-error {{cannot convert value of type 'Bool' to expected argument type '([T], [T])'}}
1317
1330
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
1331
+
1332
+ // Void function returns non-void result fix-it
1333
+
1334
+ func voidFunc( ) {
1335
+ return 1
1336
+ // expected-error@-1 {{unexpected non-void return value in void function}}
1337
+ // expected-note@-2 {{did you mean to add a return type?}}{{16-16= -> <#Return Type#>}}
1338
+ }
1339
+
1340
+ func voidFuncWithArgs( arg1: Int ) {
1341
+ return 1
1342
+ // expected-error@-1 {{unexpected non-void return value in void function}}
1343
+ // expected-note@-2 {{did you mean to add a return type?}}{{33-33= -> <#Return Type#>}}
1344
+ }
1345
+
1346
+ func voidFuncWithCondFlow( ) {
1347
+ if Bool . random ( ) {
1348
+ return 1
1349
+ // expected-error@-1 {{unexpected non-void return value in void function}}
1350
+ // expected-note@-2 {{did you mean to add a return type?}}{{28-28= -> <#Return Type#>}}
1351
+ } else {
1352
+ return 2
1353
+ // expected-error@-1 {{unexpected non-void return value in void function}}
1354
+ // expected-note@-2 {{did you mean to add a return type?}}{{28-28= -> <#Return Type#>}}
1355
+ }
1356
+ }
1357
+
1358
+ func voidFuncWithNestedVoidFunc( ) {
1359
+ func nestedVoidFunc( ) {
1360
+ return 1
1361
+ // expected-error@-1 {{unexpected non-void return value in void function}}
1362
+ // expected-note@-2 {{did you mean to add a return type?}}{{24-24= -> <#Return Type#>}}
1363
+ }
1364
+ }
1365
+
1366
+ // Special cases: These should not offer a note + fix-it
1367
+
1368
+ func voidFuncExplicitType( ) -> Void {
1369
+ return 1 // expected-error {{unexpected non-void return value in void function}}
1370
+ }
1371
+
1372
+ class ClassWithDeinit {
1373
+ deinit {
1374
+ return 0 // expected-error {{unexpected non-void return value in void function}}
1375
+ }
1376
+ }
1377
+
1378
+ class ClassWithVoidProp {
1379
+ var propertyWithVoidType : ( ) { return 5 } // expected-error {{unexpected non-void return value in void function}}
1380
+ }
1381
+
1382
+ class ClassWithPropContainingSetter {
1383
+ var propWithSetter : Int {
1384
+ get { return 0 }
1385
+ set { return 1 } // expected-error {{unexpected non-void return value in void function}}
1386
+ }
1387
+ }
0 commit comments