@@ -881,7 +881,8 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
881
881
SILValue bridgedForeignError) override {
882
882
// There should be no direct results from the call.
883
883
assert (directResults.empty ());
884
-
884
+ auto &ctx = SGF.getASTContext ();
885
+
885
886
// Await the continuation we handed off to the completion handler.
886
887
SILBasicBlock *resumeBlock = SGF.createBasicBlock ();
887
888
SILBasicBlock *errorBlock = nullptr ;
@@ -923,9 +924,20 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
923
924
SGF.B .setInsertionPoint (
924
925
++bridgedForeignError->getDefiningInstruction ()->getIterator ());
925
926
926
- auto continuationDecl = SGF.getASTContext ().getUnsafeContinuationDecl ();
927
-
928
- auto errorTy = SGF.getASTContext ().getErrorExistentialType ();
927
+ // FIXME: this case is not respecting checked bridging, and it's a
928
+ // great candidate for that. This situation comes up when bridging
929
+ // to an ObjC completion-handler method that returns a bool. It seems
930
+ // that bool indicates whether the handler was invoked. If it was not
931
+ // then it writes out an error. Here for the unsafe bridging, we're
932
+ // invoking the continuation by re-wrapping it in an
933
+ // UnsafeContinuation<_, Error> and then immediately calling its
934
+ // resume(throwing: error) method. For a checked bridging scenario, we
935
+ // would need to use a copy of the original CheckedContinuation that
936
+ // was passed to the callee. Whether that's by invoking the block
937
+ // ourselves, or just invoking the CheckedContinuation.
938
+
939
+ auto continuationDecl = ctx.getUnsafeContinuationDecl ();
940
+ auto errorTy = ctx.getErrorExistentialType ();
929
941
auto continuationBGT =
930
942
BoundGenericType::get (continuationDecl, Type (),
931
943
{calleeTypeInfo.substResultType , errorTy});
@@ -976,7 +988,7 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
976
988
977
989
Scope errorScope (SGF, loc);
978
990
979
- auto errorTy = SGF. getASTContext () .getErrorExistentialType ();
991
+ auto errorTy = ctx .getErrorExistentialType ();
980
992
auto errorVal = SGF.B .createTermResult (
981
993
SILType::getPrimitiveObjectType (errorTy), OwnershipKind::Owned);
982
994
0 commit comments