Skip to content

Commit a3df5f3

Browse files
committed
Add @_objcImpl stored property execution tests
1 parent 39455d3 commit a3df5f3

File tree

4 files changed

+113
-14
lines changed

4 files changed

+113
-14
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#import <Foundation/Foundation.h>
22

3+
NS_ASSUME_NONNULL_BEGIN
4+
35
@interface ImplClass : NSObject
46

7+
- (instancetype)init;
8+
9+
@property (assign) NSInteger implProperty;
10+
511
+ (void)runTests;
612
- (nonnull NSString *)someMethod;
713

814
@end
15+
16+
NS_ASSUME_NONNULL_END

test/Interpreter/objc_implementation.swift

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,55 @@
55
import Foundation
66

77
@_objcImplementation extension ImplClass {
8+
@objc override init() {
9+
self.implProperty = 0
10+
super.init()
11+
}
12+
13+
@objc var implProperty: Int
14+
815
@objc class func runTests() {
9-
print(ImplClass().someMethod())
10-
print(SwiftSubclass().someMethod())
16+
let impl = ImplClass()
17+
print("someMethod =", impl.someMethod())
18+
print("implProperty =", impl.implProperty)
19+
impl.implProperty = 42
20+
print("implProperty =", impl.implProperty)
21+
22+
let swiftSub = SwiftSubclass()
23+
print("someMethod =", swiftSub.someMethod())
24+
print("implProperty =", swiftSub.implProperty)
25+
swiftSub.implProperty = 42
26+
print("implProperty =", swiftSub.implProperty)
27+
28+
print("otherProperty =", swiftSub.otherProperty)
29+
swiftSub.otherProperty = 13
30+
print("otherProperty =", swiftSub.otherProperty)
31+
print("implProperty =", swiftSub.implProperty)
1132
}
1233

1334
@objc func someMethod() -> String { "ImplClass.someMethod()" }
1435
}
1536

1637
class SwiftSubclass: ImplClass {
38+
@objc var otherProperty: Int = 1
39+
40+
override init() {
41+
super.init()
42+
}
43+
1744
override func someMethod() -> String { "SwiftSubclass.someMethod()" }
1845
}
1946

2047
// `#if swift` to ignore the inactive branch's contents
2148
#if swift(>=5.0) && TOP_LEVEL_CODE
2249
ImplClass.runTests()
23-
// CHECK: ImplClass.someMethod()
24-
// CHECK: SwiftSubclass.someMethod()
50+
// CHECK: someMethod = ImplClass.someMethod()
51+
// CHECK: implProperty = 0
52+
// CHECK: implProperty = 42
53+
// CHECK: someMethod = SwiftSubclass.someMethod()
54+
// CHECK: implProperty = 0
55+
// CHECK: implProperty = 42
56+
// CHECK: otherProperty = 1
57+
// CHECK: otherProperty = 13
58+
// CHECK: implProperty = 42
2559
#endif

test/Interpreter/objc_implementation_objc_client.m

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
@interface ObjCClientSubclass : ImplClass
2727

28+
@property (assign) NSInteger otherProperty;
29+
2830
- (NSString *)someMethod;
2931

3032
@end
@@ -49,24 +51,62 @@ static void print(NSString *str) {
4951
}
5052
}
5153

54+
static void printInt(NSString *str, NSUInteger num) {
55+
NSString *fullStr =
56+
[NSString stringWithFormat:@"%@ %lld", str, (long long)num];
57+
print(fullStr);
58+
}
59+
5260
int main() {
5361
[ImplClass runTests];
54-
// CHECK: ImplClass.someMethod()
55-
// CHECK: SwiftSubclass.someMethod()
62+
// CHECK: someMethod = ImplClass.someMethod()
63+
// CHECK: implProperty = 0
64+
// CHECK: implProperty = 42
65+
// CHECK: someMethod = SwiftSubclass.someMethod()
66+
// CHECK: implProperty = 0
67+
// CHECK: implProperty = 42
68+
// CHECK: otherProperty = 1
69+
// CHECK: otherProperty = 13
70+
// CHECK: implProperty = 42
5671

5772
fflush(stdout);
5873

59-
print([[[ImplClass alloc] init] someMethod]);
74+
ImplClass *impl = [[ImplClass alloc] init];
75+
print([impl someMethod]);
6076
// CHECK: ImplClass.someMethod()
61-
62-
print([[[ObjCClientSubclass alloc] init] someMethod]);
77+
printInt(@"implProperty", impl.implProperty);
78+
// CHECK: implProperty 0
79+
impl.implProperty = -2;
80+
printInt(@"implProperty", impl.implProperty);
81+
// CHECK: implProperty -2
82+
83+
ObjCClientSubclass *objcSub = [[ObjCClientSubclass alloc] init];
84+
print([objcSub someMethod]);
6385
// CHECK: -[ObjCClientSubclass someMethod]
6486

87+
printInt(@"implProperty", objcSub.implProperty);
88+
// CHECK: implProperty 0
89+
printInt(@"otherProperty", objcSub.otherProperty);
90+
// CHECK: otherProperty 4
91+
objcSub.implProperty = 7;
92+
objcSub.otherProperty = 9;
93+
printInt(@"implProperty", objcSub.implProperty);
94+
// CHECK: implProperty 7
95+
printInt(@"otherProperty", objcSub.otherProperty);
96+
// CHECK: otherProperty 9
97+
6598
return 0;
6699
}
67100

68101
@implementation ObjCClientSubclass
69102

103+
- (id)init {
104+
if (self = [super init]) {
105+
_otherProperty = 4;
106+
}
107+
return self;
108+
}
109+
70110
- (NSString *)someMethod {
71111
return @"-[ObjCClientSubclass someMethod]";
72112
}

test/Interpreter/objc_implementation_swift_client.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,33 @@ import Foundation
3333
import objc_implementation
3434

3535
ImplClass.runTests()
36-
// CHECK: ImplClass.someMethod()
37-
// CHECK: SwiftSubclass.someMethod()
36+
// CHECK: someMethod = ImplClass.someMethod()
37+
// CHECK: implProperty = 0
38+
// CHECK: implProperty = 42
39+
// CHECK: someMethod = SwiftSubclass.someMethod()
40+
// CHECK: implProperty = 0
41+
// CHECK: implProperty = 42
42+
// CHECK: otherProperty = 1
43+
// CHECK: otherProperty = 13
44+
// CHECK: implProperty = 42
3845

39-
print(ImplClass().someMethod())
40-
// CHECK: ImplClass.someMethod()
46+
let impl = ImplClass()
47+
print(impl.someMethod(), impl.implProperty)
48+
// CHECK: ImplClass.someMethod() 0
4149

4250
class SwiftClientSubclass: ImplClass {
51+
override init() {}
52+
var otherProperty = 2
4353
override func someMethod() -> String { "SwiftClientSubclass.someMethod()" }
4454
}
4555

46-
print(SwiftClientSubclass().someMethod())
56+
let swiftClientSub = SwiftClientSubclass()
57+
print(swiftClientSub.someMethod())
4758
// CHECK: SwiftClientSubclass.someMethod()
59+
print(swiftClientSub.implProperty, swiftClientSub.otherProperty)
60+
// CHECK: 0 2
61+
swiftClientSub.implProperty = 3
62+
swiftClientSub.otherProperty = 9
63+
print(swiftClientSub.implProperty, swiftClientSub.otherProperty)
64+
// CHECK: 3 9
4865

0 commit comments

Comments
 (0)