Skip to content

Commit fd6373f

Browse files
authored
Merge pull request #3108 from hamishknight/3104-6.2
[6.2] Fix a crash if we had a dollar identifier as the second parameter label in a closure not followed by a colon
2 parents e493ab9 + 01d4f98 commit fd6373f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,13 +944,13 @@ extension Parser.Lookahead {
944944
// by a type annotation.
945945
if self.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: false) {
946946
self.consumeAnyToken()
947+
// If we have a secondary argument label, consume it.
947948
if self.atArgumentLabel() {
948949
self.consumeAnyToken()
949-
guard self.at(.colon) else {
950-
return false
951-
}
952950
}
953-
self.eat(.colon)
951+
guard self.consume(if: .colon) != nil else {
952+
return false
953+
}
954954

955955
// Parse a type.
956956
guard self.canParseType() else {

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,26 @@ final class ExpressionTests: ParserTestCase {
21452145
"""
21462146
)
21472147
}
2148+
2149+
func testSecondaryArgumentLabelDollarIdentifierInClosure() {
2150+
assertParse(
2151+
"""
2152+
ℹ️{ a1️⃣: (a $
2153+
""",
2154+
diagnostics: [
2155+
DiagnosticSpec(
2156+
message: "expected '}' to end closure",
2157+
notes: [NoteSpec(message: "to match this opening '{'")],
2158+
fixIts: ["insert '}'"]
2159+
),
2160+
DiagnosticSpec(message: "extraneous code ': (a $' at top level"),
2161+
],
2162+
fixedSource: """
2163+
{ a
2164+
}: (a $
2165+
"""
2166+
)
2167+
}
21482168
}
21492169

21502170
final class MemberExprTests: ParserTestCase {

0 commit comments

Comments
 (0)