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
SR-11261: [Diagnostics][Qol] Parser recovery for keyword (#26596)
* Fixes SR-11261
* Improving diagnostics for multi-case declaration that uses a keyword
* Only doing pattern matching if token is not a keywork or if is a possible identifier
* Using BacktrackingScope to fix expected pattern
* Updating NameLoc with the token consumed.
* Updating Name with the consumed token
Copy file name to clipboardExpand all lines: test/Parse/enum.swift
+45-6Lines changed: 45 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -101,8 +101,8 @@ enum ImproperlyHasIVars {
101
101
102
102
// We used to crash on this. rdar://14678675
103
103
enumrdar14678675{
104
-
case U1,
105
-
case U2// expected-error{{expected identifier after comma in enum 'case' declaration}}
104
+
case U1, // expected-error{{expected identifier after comma in enum 'case' declaration}}
105
+
case U2
106
106
case U3
107
107
}
108
108
@@ -125,10 +125,10 @@ enum Recovery5 {
125
125
// expected-error@-2{{extraneous '.' in enum 'case' declaration}} {{14-15=}}
126
126
}
127
127
enumRecovery6{
128
-
case Snout, _; // expected-error {{expected identifier after comma in enum 'case' declaration}}
129
-
case _; // expected-error {{keyword '_' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{8-9=`_`}}
130
-
case Tusk, // expected-error {{expected pattern}}
131
-
}// expected-error {{expected identifier after comma in enum 'case' declaration}}
128
+
case Snout, _; // expected-error {{keyword '_' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{15-16=`_`}} expected-note {{'_' previously declared here}}
129
+
case _; // expected-error {{keyword '_' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{8-9=`_`}} expected-error {{invalid redeclaration of '_'}}
130
+
case Tusk, // expected-error {{expected identifier after comma in enum 'case' declaration}}
131
+
}
132
132
133
133
enumRawTypeEmpty:Int{} // expected-error {{an enum with no cases cannot declare a raw type}} expected-note {{do you want to add protocol stubs?}}
134
134
// expected-error@-1{{'RawTypeEmpty' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
@@ -552,3 +552,42 @@ enum SE0155 {
552
552
// expected-note@-1 {{did you mean to remove the empty associated value list?}} {{17-18=}}
553
553
// expected-note@-2 {{did you mean to explicitly add a 'Void' associated value?}} {{17-17=Void}}
554
554
}
555
+
556
+
// SR-11261
557
+
enumSR11261{
558
+
case identifier
559
+
case operator // expected-error {{keyword 'operator' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{8-16=`operator`}}
560
+
case identifier2
561
+
}
562
+
563
+
enumSR11261_var{
564
+
case identifier
565
+
case var // expected-error {{keyword 'var' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{8-11=`var`}}
566
+
case identifier2
567
+
}
568
+
569
+
enumSR11261_underscore{
570
+
case identifier
571
+
case _ // expected-error {{keyword '_' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{8-9=`_`}}
572
+
case identifier2
573
+
}
574
+
575
+
enumSR11261_Comma{
576
+
case a, b, c, func, d // expected-error {{keyword 'func' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{17-21=`func`}}
577
+
}
578
+
579
+
enumSR11261_Newline{
580
+
case identifier1
581
+
case identifier2
582
+
case
583
+
case identifier // expected-error {{keyword 'case' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{3-7=`case`}}
584
+
}
585
+
586
+
enumSR11261_Newline2{
587
+
case
588
+
func foo(){} // expected-error {{keyword 'func' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{3-7=`func`}}
589
+
}
590
+
591
+
enum SR11261_PatternMatching {
592
+
case let .foo(x,y): // expected-error {{'case' label can only appear inside a 'switch' statement}}
case // expected-error {{expected identifier after comma in enum 'case' declaration}} expected-error {{expected identifier in enum 'case' declaration}} expected-error {{enum 'case' is not allowed outside of an enum}} expected-error {{expected pattern}}
640
+
case, // expected-error {{expected identifier in enum 'case' declaration}} expected-error {{expected identifier after comma in enum 'case' declaration}}
641
+
case // expected-error {{expected identifier in enum 'case' declaration}} expected-error {{enum 'case' is not allowed outside of an enum}}
642
642
// NOTE: EOF is important here to properly test a code path that used to crash the parser
0 commit comments