Skip to content

Commit d0950d1

Browse files
authored
Merge pull request #42508 from nate-chandler/test/20220420/rdar85526879
[Test] Run more returned-as-async ObjC blocks.
2 parents 9f40ebe + 15ed62d commit d0950d1

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <Foundation/Foundation.h>
2+
3+
#pragma clang assume_nonnull begin
4+
5+
@interface PFXObject : NSObject
6+
- (void)performGetStringIdentityWithCompletionHandler:
7+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull)))completionHandler;
8+
- (void)performGetStringAppendWithCompletionHandler:
9+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull)))completionHandler;
10+
- (void)performGetIntegerIdentityWithCompletionHandler:
11+
(void (^)(NSInteger(^ _Nonnull)(NSInteger)))completionHandler;
12+
- (void)performGetIntegerSubtractWithCompletionHandler:
13+
(void (^)(NSInteger(^ _Nonnull)(NSInteger, NSInteger)))completionHandler;
14+
- (void)performGetUIntegerIdentityWithCompletionHandler:
15+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger)))completionHandler;
16+
- (void)performGetUIntegerAddWithCompletionHandler:
17+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger, NSUInteger)))completionHandler;
18+
@end
19+
20+
#pragma clang assume_nonnull end
21+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "rdar85526916.h"
2+
3+
#pragma clang assume_nonnull begin
4+
5+
@implementation PFXObject
6+
- (void)performGetStringIdentityWithCompletionHandler:
7+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull)))completionHandler {
8+
completionHandler(^(NSString * _Nonnull input) {
9+
return input;
10+
});
11+
}
12+
- (void)performGetStringAppendWithCompletionHandler:
13+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull)))completionHandler {
14+
completionHandler(^(NSString * _Nonnull one, NSString * _Nonnull two) {
15+
return [one stringByAppendingString: two];
16+
});
17+
}
18+
- (void)performGetIntegerIdentityWithCompletionHandler:
19+
(void (^)(NSInteger(^ _Nonnull)(NSInteger)))completionHandler {
20+
completionHandler(^(NSInteger input) {
21+
return input;
22+
});
23+
}
24+
- (void)performGetIntegerSubtractWithCompletionHandler:
25+
(void (^)(NSInteger(^ _Nonnull)(NSInteger, NSInteger)))completionHandler {
26+
completionHandler(^(NSInteger lhs, NSInteger rhs) {
27+
return lhs - rhs;
28+
});
29+
}
30+
- (void)performGetUIntegerIdentityWithCompletionHandler:
31+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger)))completionHandler {
32+
completionHandler(^(NSUInteger input) {
33+
return input;
34+
});
35+
}
36+
- (void)performGetUIntegerAddWithCompletionHandler:
37+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger, NSUInteger)))completionHandler {
38+
completionHandler(^(NSUInteger lhs, NSUInteger rhs) {
39+
return lhs + rhs;
40+
});
41+
}
42+
@end
43+
44+
#pragma clang assume_nonnull end
45+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-clang %S/Inputs/rdar85526916.m -I %S/Inputs -c -o %t/rdar85526916.o
3+
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -import-objc-header %S/Inputs/rdar85526916.h -Xlinker %t/rdar85526916.o -parse-as-library %s -o %t/main
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: objc_interop
9+
10+
// UNSUPPORTED: use_os_stdlib
11+
// UNSUPPORTED: back_deployment_runtime
12+
13+
func run(on object: PFXObject) async throws {
14+
// CHECK: howdy
15+
print(await object.performGetStringIdentity()("howdy"))
16+
// CHECK: mundo
17+
print(await object.performGetStringAppend()("mun", "do"))
18+
// CHECK: -9035768
19+
print(await object.performGetIntegerIdentity()(-9035768))
20+
// CHECK: 57
21+
print(await object.performGetIntegerSubtract()(60, 3))
22+
// CHECK: 9035768
23+
print(await object.performGetUIntegerIdentity()(9035768))
24+
// CHECK: 3
25+
print(await object.performGetUIntegerAdd()(1+1, 1))
26+
}
27+
28+
@main struct Main {
29+
static func main() async throws {
30+
let object = PFXObject()
31+
try await run(on: object)
32+
}
33+
}
34+

0 commit comments

Comments
 (0)