Skip to content

Commit 97a5893

Browse files
authored
Merge pull request #986 from CodaFi/unsquare-dance
Consume Balanced Braces in Trailing Closure Lookahead
2 parents c1ab7e6 + f83d1d5 commit 97a5893

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,6 @@ extension Parser.Lookahead {
22942294
// {...}()
22952295
// by looking ahead for the ()'s, but this has been replaced by do{}, so this
22962296
// probably isn't worthwhile.
2297-
//
22982297
guard case .basic = flavor else {
22992298
return true
23002299
}
@@ -2317,8 +2316,8 @@ extension Parser.Lookahead {
23172316
var backtrack = self.lookahead()
23182317
backtrack.eat(.leftBrace)
23192318
var loopProgress = LoopProgressCondition()
2320-
while !backtrack.at(any: [.eof, .rightBrace]) && loopProgress.evaluate(backtrack.currentToken) {
2321-
backtrack.consumeAnyToken()
2319+
while !backtrack.at(any: [.eof, .rightBrace, .poundEndifKeyword, .poundElseKeyword, .poundElseifKeyword ]) && loopProgress.evaluate(backtrack.currentToken) {
2320+
backtrack.skipSingle()
23222321
}
23232322

23242323
guard backtrack.consume(if: .rightBrace) != nil else {

Tests/SwiftParserTest/Statements.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ final class StatementTests: XCTestCase {
4949
DiagnosticSpec(message: "unexpected code '* ! = x' in 'if' statement"),
5050
]
5151
)
52+
53+
AssertParse(
54+
"""
55+
if includeSavedHints { a = a.flatMap{ $0 } ?? nil }
56+
""")
5257
}
5358

5459
func testNestedIfs() {

0 commit comments

Comments
 (0)