Skip to content

Commit 364178f

Browse files
committed
Blocks can only be converted to AnyObject with a cast under ObjCInterop.
I don't think there's a way to test this right now because we don't actually support SwiftValue and so on except under ObjCInterop, but it's certainly more future-proof.
1 parent 0ca496c commit 364178f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,11 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,
665665
// The destination type should be AnyObject in this case.
666666
assert(bridgedType->isEqual(SGF.getASTContext().getAnyObjectType()));
667667

668-
// Blocks bridge to id with a cast.
668+
// Blocks bridge to id with a cast under ObjCInterop.
669669
if (auto nativeFnType = dyn_cast<AnyFunctionType>(nativeType)) {
670670
if (nativeFnType->getRepresentation() ==
671-
FunctionTypeRepresentation::Block) {
671+
FunctionTypeRepresentation::Block &&
672+
SGF.getASTContext().LangOpts.EnableObjCInterop) {
672673
return SGF.B.createBlockToAnyObject(loc, v, loweredBridgedTy);
673674
}
674675
}

lib/SILGen/SILGenBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ ManagedValue SILGenBuilder::createBridgeObjectToRef(SILLocation loc,
726726
ManagedValue SILGenBuilder::createBlockToAnyObject(SILLocation loc,
727727
ManagedValue v,
728728
SILType destType) {
729+
assert(SGF.getASTContext().LangOpts.EnableObjCInterop);
729730
assert(destType.isAnyObject());
730731
assert(v.getType().is<SILFunctionType>());
731732
assert(v.getType().castTo<SILFunctionType>()->getRepresentation() ==

lib/SILGen/SILGenPoly.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,9 @@ ManagedValue Transform::transform(ManagedValue v,
523523
SGF.getLoweredLoadableType(outputSubstType));
524524
}
525525

526-
// - block to AnyObject conversion
527-
if (outputSubstType->isAnyObject()) {
526+
// - block to AnyObject conversion (under ObjC interop)
527+
if (outputSubstType->isAnyObject() &&
528+
SGF.getASTContext().LangOpts.EnableObjCInterop) {
528529
if (auto inputFnType = dyn_cast<AnyFunctionType>(inputSubstType)) {
529530
if (inputFnType->getRepresentation() == FunctionTypeRepresentation::Block)
530531
return SGF.B.createBlockToAnyObject(Loc, v, loweredResultTy);

0 commit comments

Comments
 (0)