Skip to content

Commit 78a7df8

Browse files
authored
Merge pull request #85018 from beccadax/this-is-the-key-path
2 parents 2b47375 + c58c307 commit 78a7df8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/Sema/PreCheckTarget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,9 @@ void PreCheckTarget::resolveKeyPathExpr(KeyPathExpr *KPE) {
26422642
if (isa<ParenExpr>(expr) || isa<TupleExpr>(expr)) {
26432643
DE.diagnose(expr->getLoc(),
26442644
diag::expr_string_interpolation_outside_string);
2645-
} else {
2645+
} else if (!isa<ErrorExpr>(expr)) {
2646+
// If we have an `ErrorExpr`, we've probably already emitted a
2647+
// diagnostic explaining it.
26462648
DE.diagnose(expr->getLoc(),
26472649
diag::expr_swift_keypath_invalid_component);
26482650
}

test/expr/unary/keypath/keypath.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,7 @@ func f_56996() {
11861186
_ = \Int.byteSwapped.init() // expected-error {{static member 'init()' cannot be used on instance of type 'Int'}}
11871187
_ = \Int // expected-error {{key path must have at least one component}}
11881188
_ = \Int? // expected-error {{key path must have at least one component}}
1189-
_ = \Int. // expected-error {{invalid component of Swift key path}}
1190-
// expected-error@-1 {{expected member name following '.'}}
1189+
_ = \Int. // expected-error {{expected member name following '.'}}
11911190
}
11921191

11931192
// https://github.com/apple/swift/issues/55805
@@ -1439,4 +1438,4 @@ func testKeypathWithTypeReference() {
14391438
_ = \S.Q.Type.i // okay
14401439

14411440
_ = \S.Type.Q // expected-error {{key path cannot refer to type 'Q'}}
1442-
}
1441+
}

0 commit comments

Comments
 (0)