Skip to content

Commit 238b2e0

Browse files
CodaFijpsim
authored andcommitted
#keyPath Expressions Don't Actually Allow Compound Names
Somebody added this flag to improve diagnostic QoI. Instead, eat unexpected arguments in compound names as unexpected tokens and keep parsing. Fixes swiftlang#674 rdar://99430606
1 parent dc80da7 commit 238b2e0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,12 +1305,13 @@ extension Parser {
13051305
// Parse the sequence of unqualified-names.
13061306
var elements = [RawObjcNamePieceSyntax]()
13071307
do {
1308-
var flags: DeclNameOptions = .compoundNames
1308+
var flags: DeclNameOptions = []
13091309
var keepGoing: RawTokenSyntax? = nil
13101310
var loopProgress = LoopProgressCondition()
13111311
repeat {
13121312
// Parse the next name.
1313-
let (name, _) = self.parseDeclNameRef(flags)
1313+
let (name, args) = self.parseDeclNameRef(flags)
1314+
assert(args == nil, "Found arguments but did not pass argument flag?")
13141315

13151316
// After the first component, we can start parsing keywords.
13161317
flags.formUnion(.keywords)

Tests/SwiftParserTest/Expressions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ final class ExpressionTests: XCTestCase {
412412
DiagnosticSpec(message: "Expected '}' to end function"),
413413
]
414414
)
415+
416+
AssertParse("#keyPath(#^DIAG^#(b:)",
417+
diagnostics: [
418+
DiagnosticSpec(message: "Expected '' in '#keyPath' expression"),
419+
DiagnosticSpec(message: "Expected ')' to end '#keyPath' expression"),
420+
])
415421
}
416422

417423
func testMissingArrowInArrowExpr() {

0 commit comments

Comments
 (0)