Skip to content

Commit 846f159

Browse files
committed
Also check for error_type in ObjC keypath validation.
And add a test that exercises this exit path (although it won't crash a compiler without my fixes because we do end up with ErrorType in that case, not a nullptr).
1 parent e0ce5fc commit 846f159

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Sema/TypeCheckExprObjC.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
317317
// Handle property references.
318318
if (auto var = dyn_cast<VarDecl>(found)) {
319319
validateDecl(var);
320-
if (var->isInvalid() || !var->hasInterfaceType())
320+
if (var->isInvalid() || !var->hasInterfaceType() ||
321+
var->getInterfaceType()->hasError()) {
321322
return None;
323+
}
322324

323325
// Resolve this component to the variable we found.
324326
auto varRef = ConcreteDeclRef(var);

test/expr/primary/keypath/keypath-objc.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foundation
44

55
// REQUIRES: objc_interop
66

7-
@objc class A : NSObject {
7+
@objc class A : NSObject { // expected-error {{class 'A' has no initializers}}
88
@objc var propB: B = B()
99
@objc var propString: String = "" // expected-note {{did you mean 'propString'}}
1010
@objc var propArray: [String] = []
@@ -21,6 +21,8 @@ import Foundation
2121
@objc func someMethod() { }
2222

2323
@objc var `repeat`: String?
24+
25+
@objc var noType // expected-error {{type annotation missing in pattern}}
2426
}
2527

2628
@objc class B : NSObject {
@@ -106,6 +108,9 @@ func testKeyPath(a: A, b: B) {
106108
// Property with keyword name.
107109
let _: String = #keyPath(A.repeat)
108110

111+
// Property with no type
112+
let _: String = #keyPath(A.noType)
113+
109114
// Nested type of a bridged type (rdar://problem/28061409).
110115
typealias IntArray = [Int]
111116
let _: String = #keyPath(IntArray.Foo.propString)

0 commit comments

Comments
 (0)