Skip to content

Commit 25e5b15

Browse files
Add test cases for more permutations.
Make sure that we still emit warnings even if the let bindings are in different positions.
1 parent e365b6b commit 25e5b15

File tree

1 file changed

+70
-12
lines changed

1 file changed

+70
-12
lines changed

test/Sema/exhaustive_switch.swift

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,89 +1222,147 @@ enum SR11212Tests {
12221222
case upair(Int, Int)
12231223
}
12241224

1225-
func sr11212_content_untupled_pattern_tupled(u: Untupled) -> (Int, Int) {
1225+
func sr11212_content_untupled_pattern_tupled1(u: Untupled) -> (Int, Int) {
12261226
switch u {
12271227
case .upair((let x, let y)): return (x, y)
12281228
// expected-warning@-1 {{a tuple pattern cannot match several associated values at once, implicitly tupling the associated values and trying to match that instead}}
12291229
}
12301230
}
12311231

1232-
func sr11212_content_untupled_pattern_tupled_nested(u: Untupled) -> (Int, Int) {
1232+
func sr11212_content_untupled_pattern_tupled2(u: Untupled) -> (Int, Int) {
12331233
switch u {
12341234
case .upair(let (x, y)): return (x, y)
12351235
// expected-warning@-1 {{a tuple pattern cannot match several associated values at once, implicitly tupling the associated values and trying to match that instead}}
12361236
}
12371237
}
12381238

1239-
func sr11212_content_untupled_pattern_untupled(u: Untupled) -> (Int, Int) {
1239+
func sr11212_content_untupled_pattern_tupled3(u: Untupled) -> (Int, Int) {
1240+
switch u {
1241+
case let .upair((x, y)): return (x, y)
1242+
// expected-warning@-1 {{a tuple pattern cannot match several associated values at once, implicitly tupling the associated values and trying to match that instead}}
1243+
}
1244+
}
1245+
1246+
func sr11212_content_untupled_pattern_untupled1(u: Untupled) -> (Int, Int) {
12401247
switch u {
12411248
case .upair(let x, let y): return (x, y)
12421249
}
12431250
}
12441251

1245-
func sr11212_content_untupled_pattern_ambiguous(u: Untupled) -> (Int, Int) {
1252+
func sr11212_content_untupled_pattern_untupled2(u: Untupled) -> (Int, Int) {
1253+
switch u {
1254+
case let .upair(x, y): return (x, y)
1255+
}
1256+
}
1257+
1258+
func sr11212_content_untupled_pattern_ambiguous1(u: Untupled) -> (Int, Int) {
12461259
switch u {
12471260
case .upair(let u_): return u_
12481261
// expected-warning@-1 {{cannot match several associated values at once, implicitly tupling the associated values and trying to match that instead}}
12491262
}
12501263
}
12511264

1265+
func sr11212_content_untupled_pattern_ambiguous2(u: Untupled) -> (Int, Int) {
1266+
switch u {
1267+
case let .upair(u_): return u_
1268+
// expected-warning@-1 {{cannot match several associated values at once, implicitly tupling the associated values and trying to match that instead}}
1269+
}
1270+
}
1271+
12521272
enum Tupled {
12531273
case tpair((Int, Int))
12541274
}
12551275

1256-
func sr11212_content_tupled_pattern_tupled(t: Tupled) -> (Int, Int) {
1276+
func sr11212_content_tupled_pattern_tupled1(t: Tupled) -> (Int, Int) {
12571277
switch t {
12581278
case .tpair((let x, let y)): return (x, y)
12591279
}
12601280
}
12611281

1262-
func sr11212_content_tupled_pattern_tupled_nested(t: Tupled) -> (Int, Int) {
1282+
func sr11212_content_tupled_pattern_tupled2(t: Tupled) -> (Int, Int) {
12631283
switch t {
12641284
case .tpair(let (x, y)): return (x, y)
12651285
}
12661286
}
12671287

1268-
func sr11212_content_tupled_pattern_untupled(t: Tupled) -> (Int, Int) {
1288+
func sr11212_content_tupled_pattern_tupled3(t: Tupled) -> (Int, Int) {
1289+
switch t {
1290+
case let .tpair((x, y)): return (x, y)
1291+
}
1292+
}
1293+
1294+
func sr11212_content_tupled_pattern_untupled1(t: Tupled) -> (Int, Int) {
12691295
switch t {
12701296
case .tpair(let x, let y): return (x, y)
12711297
// expected-warning@-1 {{the enum case has a single tuple as an associated value, but there are several patterns here, implicitly tupling the patterns and trying to match that instead}}
12721298
}
12731299
}
12741300

1275-
func sr11212_content_tupled_pattern_ambiguous(t: Tupled) -> (Int, Int) {
1301+
func sr11212_content_tupled_pattern_untupled2(t: Tupled) -> (Int, Int) {
1302+
switch t {
1303+
case let .tpair(x, y): return (x, y)
1304+
// expected-warning@-1 {{the enum case has a single tuple as an associated value, but there are several patterns here, implicitly tupling the patterns and trying to match that instead}}
1305+
}
1306+
}
1307+
1308+
func sr11212_content_tupled_pattern_ambiguous1(t: Tupled) -> (Int, Int) {
12761309
switch t {
12771310
case .tpair(let t_): return t_
12781311
}
12791312
}
12801313

1314+
func sr11212_content_tupled_pattern_ambiguous2(t: Tupled) -> (Int, Int) {
1315+
switch t {
1316+
case let .tpair(t_): return t_
1317+
}
1318+
}
1319+
12811320
enum Box<T> {
12821321
case box(T)
12831322
}
12841323

1285-
func sr11212_content_generic_pattern_tupled(b: Box<(Int, Int)>) -> (Int, Int) {
1324+
func sr11212_content_generic_pattern_tupled1(b: Box<(Int, Int)>) -> (Int, Int) {
12861325
switch b {
12871326
case .box((let x, let y)): return (x, y)
12881327
}
12891328
}
12901329

1291-
func sr11212_content_generic_pattern_tupled_nested(b: Box<(Int, Int)>) -> (Int, Int) {
1330+
func sr11212_content_generic_pattern_tupled2(b: Box<(Int, Int)>) -> (Int, Int) {
12921331
switch b {
12931332
case .box(let (x, y)): return (x, y)
12941333
}
12951334
}
12961335

1297-
func sr11212_content_generic_pattern_untupled(b: Box<(Int, Int)>) -> (Int, Int) {
1336+
func sr11212_content_generic_pattern_tupled3(b: Box<(Int, Int)>) -> (Int, Int) {
1337+
switch b {
1338+
case let .box((x, y)): return (x, y)
1339+
}
1340+
}
1341+
1342+
func sr11212_content_generic_pattern_untupled1(b: Box<(Int, Int)>) -> (Int, Int) {
12981343
switch b {
12991344
case .box(let x, let y): return (x, y)
13001345
// expected-warning@-1 {{the enum case has a single tuple as an associated value, but there are several patterns here, implicitly tupling the patterns and trying to match that instead}}
13011346
}
13021347
}
13031348

1304-
func sr11212_content_generic_pattern_ambiguous(b: Box<(Int, Int)>) -> (Int, Int) {
1349+
func sr11212_content_generic_pattern_untupled2(b: Box<(Int, Int)>) -> (Int, Int) {
1350+
switch b {
1351+
case let .box(x, y): return (x, y)
1352+
// expected-warning@-1 {{the enum case has a single tuple as an associated value, but there are several patterns here, implicitly tupling the patterns and trying to match that instead}}
1353+
}
1354+
}
1355+
1356+
func sr11212_content_generic_pattern_ambiguous1(b: Box<(Int, Int)>) -> (Int, Int) {
13051357
switch b {
13061358
case .box(let b_): return b_
13071359
}
13081360
}
13091361

1362+
func sr11212_content_generic_pattern_ambiguous2(b: Box<(Int, Int)>) -> (Int, Int) {
1363+
switch b {
1364+
case let .box(b_): return b_
1365+
}
1366+
}
1367+
13101368
} // end SR11212Tests

0 commit comments

Comments
 (0)