You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Must be a single pattern
- Must be last in the switch
- Must not have a 'where' clause
- Must specifically be the "any" pattern if using 'case'
We may lift some of these restrictions in the future, but that would
need a new proposal.
Copy file name to clipboardExpand all lines: test/Parse/switch.swift
+61-1Lines changed: 61 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -388,7 +388,7 @@ case .Thing:
388
388
switchWhatever.Thing {
389
389
default:
390
390
x =0
391
-
@unknowncase _: // expected-error{{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}}
391
+
@unknowncase _: // expected-error{{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}} expected-error {{'@unknown' can only be applied to the last case in a switch}}
392
392
x =0
393
393
case.Thing:
394
394
x =0
@@ -413,6 +413,66 @@ switch Whatever.Thing { // expected-warning {{switch must be exhaustive}} expect
413
413
fallthrough // expected-error{{'fallthrough' without a following 'case' or 'default' block}}
414
414
}
415
415
416
+
switchWhatever.Thing {
417
+
@unknowncase _: // expected-error {{'@unknown' can only be applied to the last case in a switch}}
418
+
fallthrough
419
+
case.Thing:
420
+
break
421
+
}
422
+
423
+
switchWhatever.Thing {
424
+
@unknowndefault:
425
+
fallthrough
426
+
case.Thing: // expected-error{{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}}
427
+
break
428
+
}
429
+
430
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
431
+
@unknowncase _, _: // expected-error {{'@unknown' cannot be applied to multiple patterns}}
432
+
break
433
+
}
434
+
435
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
436
+
@unknowncase _, _, _: // expected-error {{'@unknown' cannot be applied to multiple patterns}}
437
+
break
438
+
}
439
+
440
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
441
+
@unknowncaselet value: // expected-error {{'@unknown' is only supported for catch-all cases ("case _")}}
442
+
_ = value
443
+
}
444
+
445
+
switch(Whatever.Thing,Whatever.Thing){ // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '(_, _)'}}
446
+
@unknowncase(_, _): // expected-error {{'@unknown' is only supported for catch-all cases ("case _")}}
447
+
break
448
+
}
449
+
450
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
451
+
@unknowncase is Whatever: // expected-error {{'@unknown' is only supported for catch-all cases ("case _")}}
452
+
// expected-warning@-1 {{'is' test is always true}}
453
+
break
454
+
}
455
+
456
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
457
+
@unknowncase.Thing: // expected-error {{'@unknown' is only supported for catch-all cases ("case _")}}
458
+
break
459
+
}
460
+
461
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
462
+
@unknowncase(_): // okay
463
+
break
464
+
}
465
+
466
+
switchWhatever.Thing { // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
467
+
@unknowncase _ where x ==0: // expected-error {{'where' cannot be used with '@unknown'}}
468
+
break
469
+
}
470
+
471
+
switch Whatever.Thing{ // expected-warning {{switch must be exhaustive}} expected-note{{add missing case: '.Thing'}}
472
+
@unknown default where x ==0: // expected-error {{'default' cannot be used with a 'where' guard expression}}
0 commit comments