Skip to content

Commit db32480

Browse files
authored
Merge pull request #10050 from jckarter/class-extension-access-strategy
Correct getAccessStrategy for class extension storage decls.
2 parents ea5a42d + 2c0873a commit db32480

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,13 @@ static bool isPolymorphic(const AbstractStorageDecl *storage) {
11651165

11661166
case DeclKind::Class:
11671167
// Final properties can always be direct, even in classes.
1168-
return !storage->isFinal();
1168+
if (storage->isFinal())
1169+
return false;
1170+
// Extension properties are statically dispatched, unless they're @objc.
1171+
if (storage->getDeclContext()->isExtensionContext()
1172+
&& !storage->isObjC())
1173+
return false;
1174+
return true;
11691175
}
11701176
llvm_unreachable("bad DeclKind");
11711177
}

test/SILGen/keypaths_objc.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-keypath-components -emit-silgen -import-objc-header %S/Inputs/keypaths_objc.h %s | %FileCheck %s
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-keypath-components -emit-ir -import-objc-header %S/Inputs/keypaths_objc.h %s
23
// REQUIRES: objc_interop
34

45
import Foundation
@@ -55,3 +56,23 @@ func objcKeypathIdentifiers() {
5556
// CHECK: keypath $KeyPath<Foo, Int>, (objc "int"; {{.*}} id #Foo.int!getter.1 :
5657
_ = \Foo.int
5758
}
59+
60+
struct X {}
61+
62+
extension NSObject {
63+
var x: X { return X() }
64+
@objc var objc: Int { return 0 }
65+
@objc dynamic var dynamic: Int { return 0 }
66+
}
67+
68+
// CHECK-LABEL: sil hidden @{{.*}}nonobjcExtensionOfObjCClass
69+
func nonobjcExtensionOfObjCClass() {
70+
// Should be treated as a statically-dispatch property
71+
// CHECK: keypath $KeyPath<NSObject, X>, ({{.*}} id @
72+
_ = \NSObject.x
73+
// CHECK: keypath $KeyPath<NSObject, Int>, ({{.*}} id #NSObject.objc!getter.1.foreign
74+
_ = \NSObject.objc
75+
// CHECK: keypath $KeyPath<NSObject, Int>, ({{.*}} id #NSObject.dynamic!getter.1.foreign
76+
_ = \NSObject.dynamic
77+
78+
}

0 commit comments

Comments
 (0)