Skip to content

Emit diagnostic when missing label in function call #2442

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
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
4 changes: 4 additions & 0 deletions Sources/SwiftParser/Expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,10 @@ extension Parser {
if self.atArgumentLabel(allowDollarIdentifier: true) && self.peek(isAt: .colon) {
(unexpectedBeforeLabel, label) = parseArgumentLabel()
colon = consumeAnyToken()
} else if let _colon = self.consume(if: .colon) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added _colon here otherwise it will clash with name with on 1860

unexpectedBeforeLabel = nil
label = RawTokenSyntax(missing: .identifier, arena: self.arena)
colon = _colon
} else {
unexpectedBeforeLabel = nil
label = nil
Expand Down
13 changes: 13 additions & 0 deletions Tests/SwiftParserTest/ExpressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2977,4 +2977,17 @@ final class StatementExpressionTests: ParserTestCase {
substructure: AttributeSyntax(attributeName: TypeSyntax("Sendable"))
)
}

func testFunctionWithMissingLabel() {
assertParse(
"foo(1️⃣: 1)",
diagnostics: [
DiagnosticSpec(
message: "expected label in function call",
fixIts: ["insert label"]
)
],
fixedSource: "foo(<#identifier#>: 1)"
)
}
}