Skip to content

Fix a crash if we had a dollar identifier as the second parameter label in a closure not followed by a colon #3104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/SwiftParser/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,13 @@ extension Parser.Lookahead {
// by a type annotation.
if self.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: false) {
self.consumeAnyToken()
// If we have a secondary argument label, consume it.
if self.atArgumentLabel() {
self.consumeAnyToken()
guard self.at(.colon) else {
return false
}
}
self.eat(.colon)
guard self.consume(if: .colon) != nil else {
return false
}

// Parse a type.
guard self.canParseType() else {
Expand Down
20 changes: 20 additions & 0 deletions Tests/SwiftParserTest/ExpressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,26 @@ final class ExpressionTests: ParserTestCase {
"""
)
}

func testSecondaryArgumentLabelDollarIdentifierInClosure() {
assertParse(
"""
ℹ️{ a1️⃣: (a $
""",
diagnostics: [
DiagnosticSpec(
message: "expected '}' to end closure",
notes: [NoteSpec(message: "to match this opening '{'")],
fixIts: ["insert '}'"]
),
DiagnosticSpec(message: "extraneous code ': (a $' at top level"),
],
fixedSource: """
{ a
}: (a $
"""
)
}
}

final class MemberExprTests: ParserTestCase {
Expand Down
Loading