Skip to content

Commit e29a2f6

Browse files
committed
Add diagnostic message for identifier editor placeholder
1 parent 5594b98 commit e29a2f6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/SwiftParser/Parser.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ extension Parser {
412412
keywordRecovery: Bool = false
413413
) -> (RawUnexpectedNodesSyntax?, RawTokenSyntax) {
414414
if allowIdentifierLikeKeywords {
415-
if let (_, handle) = self.canRecoverTo(anyIn: IdentifierTokens.self) {
415+
if currentToken.isEditorPlaceholder {
416+
return (
417+
RawUnexpectedNodesSyntax(elements: [RawSyntax(self.consumeAnyToken())], arena: self.arena),
418+
self.missingToken(.identifier, text: nil)
419+
)
420+
} else if let (_, handle) = self.canRecoverTo(anyIn: IdentifierTokens.self) {
416421
return self.eat(handle)
417422
}
418423
} else {

Tests/SwiftParserTest/translated/IdentifiersTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ final class IdentifiersTests: XCTestCase {
8383
AssertParse(
8484
"""
8585
// Placeholders are recognized as identifiers but with error.
86-
func <#some name#>() {}
86+
func 1️⃣<#some name#>() {}
8787
""",
8888
diagnostics: [
89+
DiagnosticSpec(message: "editor placeholder in source file")
8990
// TODO: (good first issue) Old parser expected error on line 2: editor placeholder in source file
9091
]
9192
)

0 commit comments

Comments
 (0)