Skip to content

Commit 31d0647

Browse files
committed
Handle unexpected token before in keyword
1 parent fa9da0a commit 31d0647

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,17 @@ enum TokenPrecedence: Comparable {
203203
// Consider 'any' a prefix operator to a type and a type is expression-like.
204204
.Any,
205205
// 'where' can only occur in the signature of declarations. Consider the signature expression-like.
206-
.where,
207-
// 'in' occurs in closure input/output definitions and for loops. Consider both constructs expression-like.
208-
.in:
206+
.where:
209207
self = .exprKeyword
210208

211209
case // Control-flow constructs
212210
.defer, .do, .for, .guard, .if, .repeat, .switch, .while,
213211
// Secondary parts of control-flow constructs
214212
.case, .catch, .default, .else,
215213
// Return-like statements
216-
.break, .continue, .fallthrough, .return, .throw, .then, .yield:
214+
.break, .continue, .fallthrough, .return, .throw, .then, .yield,
215+
// 'in' occurs in closure input/output definitions and for loops. Consider both constructs expression-like.
216+
.in:
217217
self = .stmtKeyword
218218

219219
// MARK: Decl keywords

Tests/SwiftParserTest/StatementTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,4 +921,13 @@ final class StatementTests: ParserTestCase {
921921
"""
922922
)
923923
}
924+
925+
func testForStatementWithUnexpectedTokenBeforeInKeyword() {
926+
assertParse(
927+
"for var elem1️⃣? in arr { }",
928+
diagnostics: [
929+
DiagnosticSpec(message: "unexpected code '?' in 'for' statement")
930+
]
931+
)
932+
}
924933
}

0 commit comments

Comments
 (0)