Skip to content

Commit 9a91a44

Browse files
committed
Support initial values for stored properties of @_objcImplementation.
Fixes rdar://106108285.
1 parent 40573ad commit 9a91a44

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/SILGen/SILGenType.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,13 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
13321332
void visitPatternBindingDecl(PatternBindingDecl *pd) {
13331333
// Emit initializers for static variables.
13341334
for (auto i : range(pd->getNumPatternEntries())) {
1335-
if (pd->getExecutableInit(i) && pd->isStatic()) {
1336-
SGM.emitGlobalInitialization(pd, i);
1335+
if (pd->getExecutableInit(i)) {
1336+
if (pd->isStatic())
1337+
SGM.emitGlobalInitialization(pd, i);
1338+
else if (isa<ExtensionDecl>(pd->getDeclContext()) &&
1339+
cast<ExtensionDecl>(pd->getDeclContext())
1340+
->isObjCImplementation())
1341+
SGM.emitStoredPropertyInitialization(pd, i);
13371342
}
13381343
}
13391344
}

test/Interpreter/Inputs/objc_implementation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN
77
- (instancetype)init;
88

99
@property (assign) NSInteger implProperty;
10+
@property (assign) NSInteger defaultIntProperty;
1011

1112
+ (void)runTests;
1213
- (nonnull NSString *)someMethod;

test/Interpreter/objc_implementation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class LastWords {
2727

2828
@objc var implProperty: Int
2929
final var object: LastWords
30+
final weak var defaultNilProperty: AnyObject?
31+
@objc var defaultIntProperty: Int = 17
3032

3133
@objc class func runTests() {
3234
do {
@@ -35,6 +37,7 @@ class LastWords {
3537
print("implProperty =", impl.implProperty)
3638
impl.implProperty = 42
3739
print("implProperty =", impl.implProperty)
40+
print("defaultIntProperty =", impl.defaultIntProperty)
3841
print("description =", impl.description)
3942
}
4043

@@ -44,6 +47,7 @@ class LastWords {
4447
print("implProperty =", swiftSub.implProperty)
4548
swiftSub.implProperty = 42
4649
print("implProperty =", swiftSub.implProperty)
50+
print("defaultIntProperty =", swiftSub.defaultIntProperty)
4751

4852
print("otherProperty =", swiftSub.otherProperty)
4953
swiftSub.otherProperty = 13
@@ -75,11 +79,13 @@ ImplClass.runTests()
7579
// CHECK: someMethod = ImplClass.someMethod()
7680
// CHECK: implProperty = 0
7781
// CHECK: implProperty = 42
82+
// CHECK: defaultIntProperty = 17
7883
// CHECK: description = ImplClass(implProperty: 42, object: main.LastWords)
7984
// CHECK: ImplClass It's better to burn out than to fade away.
8085
// CHECK: someMethod = SwiftSubclass.someMethod()
8186
// CHECK: implProperty = 0
8287
// CHECK: implProperty = 42
88+
// CHECK: defaultIntProperty = 17
8389
// CHECK: otherProperty = 1
8490
// CHECK: otherProperty = 13
8591
// CHECK: implProperty = 42

0 commit comments

Comments
 (0)