diff --git a/lib/Sema/PreCheckTarget.cpp b/lib/Sema/PreCheckTarget.cpp index 0c598db8155b2..d77f2cda6ce18 100644 --- a/lib/Sema/PreCheckTarget.cpp +++ b/lib/Sema/PreCheckTarget.cpp @@ -2642,7 +2642,9 @@ void PreCheckTarget::resolveKeyPathExpr(KeyPathExpr *KPE) { if (isa(expr) || isa(expr)) { DE.diagnose(expr->getLoc(), diag::expr_string_interpolation_outside_string); - } else { + } else if (!isa(expr)) { + // If we have an `ErrorExpr`, we've probably already emitted a + // diagnostic explaining it. DE.diagnose(expr->getLoc(), diag::expr_swift_keypath_invalid_component); } diff --git a/test/expr/unary/keypath/keypath.swift b/test/expr/unary/keypath/keypath.swift index 70ddd03b5feb3..331e89eac8512 100644 --- a/test/expr/unary/keypath/keypath.swift +++ b/test/expr/unary/keypath/keypath.swift @@ -1186,8 +1186,7 @@ func f_56996() { _ = \Int.byteSwapped.init() // expected-error {{static member 'init()' cannot be used on instance of type 'Int'}} _ = \Int // expected-error {{key path must have at least one component}} _ = \Int? // expected-error {{key path must have at least one component}} - _ = \Int. // expected-error {{invalid component of Swift key path}} - // expected-error@-1 {{expected member name following '.'}} + _ = \Int. // expected-error {{expected member name following '.'}} } // https://github.com/apple/swift/issues/55805 @@ -1439,4 +1438,4 @@ func testKeypathWithTypeReference() { _ = \S.Q.Type.i // okay _ = \S.Type.Q // expected-error {{key path cannot refer to type 'Q'}} -} \ No newline at end of file +}