Skip to content

Commit 63613a9

Browse files
authored
Merge pull request #37348 from jckarter/runtime-test-async-objc-method-completion-handler-override
Add test that exercises still overriding ObjC async methods as completion handlers
2 parents 420afdc + 391a3bd commit 63613a9

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

test/Concurrency/Runtime/Inputs/objc_async.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
@end
1010

11+
@interface MutableButt: Butt
12+
@end
13+
14+
@interface MutableButt_2Fast2Furious: MutableButt
15+
@end
16+
1117
@interface Farm: NSObject
1218

1319
-(void)getDogWithCompletion:(void (^ _Nonnull)(NSInteger))completionHandler

test/Concurrency/Runtime/Inputs/objc_async.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ - (void)butt:(NSInteger)x completionHandler:(void (^)(NSInteger))handler {
1414

1515
@end
1616

17+
@implementation MutableButt: Butt
18+
@end
19+
20+
@implementation MutableButt_2Fast2Furious: MutableButt
21+
@end
22+
23+
1724
@implementation Farm
1825

1926
-(void)getDogWithCompletion:(void (^ _Nonnull)(NSInteger))completionHandler {
@@ -30,7 +37,7 @@ -(void)obtainCat:(void (^ _Nonnull)(NSInteger, NSError* _Nullable))completionHan
3037

3138
void scheduleButt(Butt *b, NSString *s) {
3239
[b butt: 1738 completionHandler: ^(NSInteger i) {
33-
printf("butt %p named %s occurred at %zd", b, [s UTF8String], (ssize_t)i);
40+
printf("butt %p named %s occurred at %zd\n", b, [s UTF8String], (ssize_t)i);
3441
fflush(stdout);
3542
}];
3643
}

test/Concurrency/Runtime/objc_async.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ func farmTest() async {
3131
class Clbuttic: Butt {
3232
override func butt(_ x: Int) async -> Int {
3333
print("called into override")
34-
return 679
34+
return 219
35+
}
36+
}
37+
38+
class Buttertion: MutableButt_2Fast2Furious {
39+
override func butt(_ x: Int, completionHandler: @escaping (Int) -> Void) {
40+
print("called again into override")
41+
completionHandler(20721)
3542
}
3643
}
3744

@@ -48,10 +55,16 @@ class Clbuttic: Butt {
4855
await farmTest()
4956

5057
// CHECK-NEXT: called into override
51-
// CHECK-NEXT: butt {{.*}} named clbuttic occurred at 679
58+
// CHECK-NEXT: butt {{.*}} named clbuttic occurred at 219
5259
scheduleButt(Clbuttic(), "clbuttic")
5360

54-
await Task.sleep(500_000)
61+
await Task.sleep(250_000)
62+
63+
// CHECK-NEXT: called again into override
64+
// CHECK-NEXT: butt {{.*}} named buttertion occurred at 20721
65+
scheduleButt(Buttertion(), "buttertion")
66+
67+
await Task.sleep(250_000)
5568
}
5669
}
5770

0 commit comments

Comments
 (0)