Skip to content

Commit 3132c32

Browse files
committed
#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 #674 rdar://99430606
1 parent ac6f92b commit 3132c32

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
@@ -1282,11 +1282,12 @@ extension Parser {
12821282
// Parse the sequence of unqualified-names.
12831283
var elements = [RawObjcNamePieceSyntax]()
12841284
do {
1285-
var flags: DeclNameOptions = .compoundNames
1285+
var flags: DeclNameOptions = []
12861286
var keepGoing: RawTokenSyntax? = nil
12871287
repeat {
12881288
// Parse the next name.
1289-
let (name, _) = self.parseDeclNameRef(flags)
1289+
let (name, args) = self.parseDeclNameRef(flags)
1290+
assert(args == nil, "Found arguments but did not pass argument flag?")
12901291

12911292
// After the first component, we can start parsing keywords.
12921293
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)