@@ -820,7 +820,7 @@ func returnBranches6() -> Int {
820
820
case true :
821
821
print ( " hello " )
822
822
0 // expected-warning {{integer literal is unused}}
823
- // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw'}}
823
+ // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
824
824
case false :
825
825
1
826
826
}
@@ -835,7 +835,7 @@ func returnBranches6PoundIf() -> Int {
835
835
print ( " hello " )
836
836
0 // expected-warning {{integer literal is unused}}
837
837
#endif
838
- // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw'}}
838
+ // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
839
839
case false :
840
840
1
841
841
}
@@ -850,7 +850,7 @@ func returnBranches6PoundIf2() -> Int {
850
850
print ( " hello " )
851
851
0
852
852
#endif
853
- // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw'}}
853
+ // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
854
854
case false :
855
855
1
856
856
}
@@ -882,7 +882,7 @@ func returnBranches9() -> Int {
882
882
let i = switch Bool . random ( ) {
883
883
case true :
884
884
print ( " hello " )
885
- if . random( ) { } // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw'}}
885
+ if . random( ) { } // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
886
886
case false :
887
887
1
888
888
}
@@ -898,7 +898,7 @@ func returnBranches10() -> Int {
898
898
0 // expected-warning {{integer literal is unused}}
899
899
case false :
900
900
2 // expected-warning {{integer literal is unused}}
901
- } // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw'}}
901
+ } // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
902
902
case false :
903
903
1
904
904
}
@@ -914,7 +914,7 @@ func returnBranches11() -> Int {
914
914
" " // expected-warning {{string literal is unused}}
915
915
case false :
916
916
2 // expected-warning {{integer literal is unused}}
917
- } // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw'}}
917
+ } // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
918
918
case false :
919
919
1
920
920
}
@@ -1059,7 +1059,7 @@ func testPoundIfBranch3() -> Int {
1059
1059
#if false
1060
1060
0
1061
1061
#endif
1062
- // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw'}}
1062
+ // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
1063
1063
case false :
1064
1064
0
1065
1065
}
@@ -1100,7 +1100,7 @@ func testPoundIfBranch6() -> Int {
1100
1100
0
1101
1101
#endif
1102
1102
0 // expected-warning {{integer literal is unused}}
1103
- // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw'}}
1103
+ // expected-error@-1 {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough' }}
1104
1104
case false :
1105
1105
1
1106
1106
}
@@ -1180,6 +1180,38 @@ func fallthrough2() -> Int {
1180
1180
return x
1181
1181
}
1182
1182
1183
+ func fallthrough3( ) -> Int {
1184
+ let x = switch true {
1185
+ case true :
1186
+ fallthrough
1187
+ case false :
1188
+ 0
1189
+ }
1190
+ return x
1191
+ }
1192
+
1193
+ func fallthrough4( ) -> Int {
1194
+ let x = switch true {
1195
+ case true :
1196
+ fallthrough
1197
+ return 0 // expected-error {{cannot use 'return' to transfer control out of 'switch' expression}}
1198
+ case false :
1199
+ 0
1200
+ }
1201
+ return x
1202
+ }
1203
+
1204
+ func fallthrough5( ) -> Int {
1205
+ let x = switch true {
1206
+ case true :
1207
+ fallthrough
1208
+ print ( 0 ) // expected-error {{non-expression branch of 'switch' expression may only end with a 'throw' or 'fallthrough'}}
1209
+ case false :
1210
+ 0
1211
+ }
1212
+ return x
1213
+ }
1214
+
1183
1215
func breakAfterNeverExpr( ) -> String {
1184
1216
// We avoid turning this into a switch expression because of the 'break'.
1185
1217
switch Bool . random ( ) {
0 commit comments