Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix a crash if we had a dollar identifier as the second parameter lab…
…el in a closure not followed by a colon There was a mismatch between the call to `eat` and `at`. Switch the pair to a `consume(if:)` to avoid the issue. Fixes #3103
  • Loading branch information
ahoppen committed Jun 16, 2025
commit 902e76e4c8c3d0e65b7c1b3b3dde6a3a925853a5
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