File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -188,11 +188,6 @@ extension Parser {
188
188
} else if self . atStartOfExpression ( ) {
189
189
item = . expr( self . parseExpression ( flavor: . basic, pattern: . none) )
190
190
attachSemi = true
191
- } else if ( self . at ( . atSign) && peek ( isAt: . identifier) ) || self . at ( anyIn: DeclarationModifier . self) != nil {
192
- // Force parsing '@<identifier>' as a declaration, as there's no valid
193
- // expression or statement starting with an attribute.
194
- item = . decl( self . parseDeclaration ( ) )
195
- attachSemi = true
196
191
} else if self . withLookahead ( { $0. atStartOfSwitchCase ( ) } ) {
197
192
// 'case' and 'default' are invalid in code block items.
198
193
// Parse them and put them in their own CodeBlockItem but as an unexpected node.
@@ -203,6 +198,11 @@ extension Parser {
203
198
semicolon: nil ,
204
199
arena: self . arena
205
200
)
201
+ } else if ( self . at ( . atSign) && peek ( isAt: . identifier) ) || self . at ( anyIn: DeclarationModifier . self) != nil {
202
+ // Force parsing '@<identifier>' as a declaration, as there's no valid
203
+ // expression or statement starting with an attribute.
204
+ item = . decl( self . parseDeclaration ( ) )
205
+ attachSemi = true
206
206
} else {
207
207
// Otherwise, eat the unexpected tokens into an "decl".
208
208
item = . decl(
Original file line number Diff line number Diff line change @@ -257,6 +257,20 @@ final class StatementTests: ParserTestCase {
257
257
)
258
258
}
259
259
260
+ func testUnknownDefaultAtStatement( ) {
261
+ assertParse (
262
+ """
263
+ func test() {
264
+ 1️⃣@unknown default:
265
+ return
266
+ }
267
+ """ ,
268
+ diagnostics: [
269
+ DiagnosticSpec ( message: " 'default' label can only appear inside a 'switch' statement " )
270
+ ]
271
+ )
272
+ }
273
+
260
274
func testMissingIfClauseIntroducer( ) {
261
275
assertParse ( " if _ = 42 {} " )
262
276
}
You can’t perform that action at this time.
0 commit comments