Skip to content

Commit 8309ae8

Browse files
authored
Merge pull request #7043 from jrose-apple/swift-3.1-keyPath-interface-types
Use interface types when checking #keyPath. (#7028)
2 parents 7baaeae + a2f29b6 commit 8309ae8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/TypeCheckExprObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
289289

290290
// Resolve this component to the variable we found.
291291
expr->resolveComponent(idx, var);
292-
updateState(/*isProperty=*/true, var->getType()->getRValueObjectType());
292+
updateState(/*isProperty=*/true,
293+
var->getInterfaceType()->getRValueObjectType());
293294

294295
// Check that the property is @objc.
295296
if (!var->isObjC()) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: %target-swift-frontend -emit-module %s -DLIBRARY -o %t/Lib.swiftmodule
3+
// RUN: %target-swift-frontend -typecheck %s -I %t -verify
4+
5+
// REQUIRES: objc_interop
6+
7+
#if LIBRARY
8+
9+
import Foundation
10+
public class Test: NSObject {
11+
@objc public var prop: NSObject?
12+
}
13+
14+
#else
15+
16+
import Lib
17+
18+
func test() {
19+
_ = #keyPath(Test.prop) // okay
20+
_ = #keyPath(Test.nonexistent) // expected-error {{type 'Test' has no member 'nonexistent'}}
21+
}
22+
23+
#endif

0 commit comments

Comments
 (0)