Skip to content

Commit 9959914

Browse files
authored
Merge pull request swiftlang#35720 from jckarter/async-unbridged-result-optional-unwrap
SILGen: Unwrap optional async callback arguments if imported return is unbridged and not optional
2 parents c269d00 + 8a81052 commit 9959914

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

lib/SILGen/SILGenThunk.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
315315
// FIXME: pass down formal type
316316
destBuf->getType().getASTType(),
317317
destBuf->getType().getObjectType());
318+
// Force-unwrap an argument that comes to us as Optional if it's
319+
// formally non-optional in the return.
320+
if (bridgedArg.getType().getOptionalObjectType()
321+
&& !destBuf->getType().getOptionalObjectType()) {
322+
bridgedArg = SGF.emitPreconditionOptionalHasValue(loc,
323+
bridgedArg,
324+
/*implicit*/ true);
325+
}
318326
bridgedArg.forwardInto(SGF, loc, destBuf);
319327
};
320328

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
5151
// rdar://72604599
5252
- (void)stopRecordingWithHandler:(nullable void (^)(NSObject *_Nullable_result x, NSError *_Nullable error))handler __attribute__((swift_async_name("stopRecording()"))) __attribute__((swift_async(not_swift_private, 1)));
5353

54+
// rdar://73798726
55+
- (void)getSomeObjectWithCompletionHandler:(nullable void (^)(NSObject *_Nullable x, NSError *_Nullable error))handler;
5456
@end
5557

5658
@protocol RefrigeratorDelegate<NSObject>

test/SILGen/objc_async.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func testSlowServer(slowServer: SlowServer) async throws {
6161
let _: String = try await slowServer.doSomethingDangerousNullably("foo")
6262

6363
let _: NSObject? = try await slowServer.stopRecording()
64+
let _: NSObject = try await slowServer.someObject()
6465
}
6566

6667
// CHECK: sil{{.*}}@[[INT_COMPLETION_BLOCK]]

0 commit comments

Comments
 (0)