File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,18 @@ bool Parser::isStartOfStmt() {
92
92
// putting a label on something inappropriate in parseStmt().
93
93
return isStartOfStmt ();
94
94
}
95
+
96
+ case tok::at_sign: {
97
+ // Might be a statement or case attribute. The only one of these we have
98
+ // right now is `@unknown default`, so hardcode a check for an attribute
99
+ // without any parens.
100
+ if (!peekToken ().is (tok::identifier))
101
+ return false ;
102
+ Parser::BacktrackingScope backtrack (*this );
103
+ consumeToken (tok::at_sign);
104
+ consumeToken (tok::identifier);
105
+ return isStartOfStmt ();
106
+ }
95
107
}
96
108
}
97
109
Original file line number Diff line number Diff line change @@ -609,3 +609,38 @@ switch x {
609
609
@unknown default : // expected-error {{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}}
610
610
break
611
611
}
612
+
613
+ func testReturnBeforeUnknownDefault( ) {
614
+ switch x { // expected-error {{switch must be exhaustive}}
615
+ case 1 :
616
+ return
617
+ @unknown default : // expected-note {{remove '@unknown' to handle remaining values}}
618
+ break
619
+ }
620
+ }
621
+
622
+ func testReturnBeforeIncompleteUnknownDefault( ) {
623
+ switch x { // expected-error {{switch must be exhaustive}}
624
+ case 1 :
625
+ return
626
+ @unknown default // expected-error {{expected ':' after 'default'}}
627
+ // expected-note@-1 {{remove '@unknown' to handle remaining values}}
628
+ }
629
+ }
630
+
631
+ func testReturnBeforeIncompleteUnknownDefault2( ) {
632
+ switch x { // expected-error {{switch must be exhaustive}} expected-note {{do you want to add a default clause?}}
633
+ case 1 :
634
+ return
635
+ @unknown // expected-error {{unknown attribute 'unknown'}}
636
+ } // expected-error {{expected declaration}}
637
+ }
638
+
639
+ func testIncompleteArrayLiteral( ) {
640
+ switch x { // expected-error {{switch must be exhaustive}}
641
+ case 1 :
642
+ _ = [ 1 // expected-error {{expected ']' in container literal expression}} expected-note {{to match this opening '['}}
643
+ @unknown default : // expected-note {{remove '@unknown' to handle remaining values}}
644
+ ( )
645
+ }
646
+ }
You can’t perform that action at this time.
0 commit comments