@@ -974,8 +974,8 @@ namespace {
974
974
// Convert the type arguments.
975
975
for (auto typeArg : typeArgs) {
976
976
Type importedTypeArg = Impl.importTypeIgnoreIUO (
977
- typeArg, ImportTypeKind::BridgedValue, AllowNSUIntegerAsInt ,
978
- Bridging, OTK_None);
977
+ typeArg, ImportTypeKind::ObjCCollectionElement ,
978
+ AllowNSUIntegerAsInt, Bridging, OTK_None);
979
979
if (!importedTypeArg) {
980
980
importedTypeArgs.clear ();
981
981
break ;
@@ -1102,7 +1102,7 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
1102
1102
case ImportTypeKind::CFUnretainedOutParameter:
1103
1103
case ImportTypeKind::Property:
1104
1104
case ImportTypeKind::PropertyWithReferenceSemantics:
1105
- case ImportTypeKind::BridgedValue :
1105
+ case ImportTypeKind::ObjCCollectionElement :
1106
1106
case ImportTypeKind::Typedef:
1107
1107
return true ;
1108
1108
}
@@ -1116,7 +1116,7 @@ static bool isCFAudited(ImportTypeKind importKind) {
1116
1116
case ImportTypeKind::Abstract:
1117
1117
case ImportTypeKind::Typedef:
1118
1118
case ImportTypeKind::Value:
1119
- case ImportTypeKind::BridgedValue :
1119
+ case ImportTypeKind::ObjCCollectionElement :
1120
1120
case ImportTypeKind::Variable:
1121
1121
case ImportTypeKind::Result:
1122
1122
case ImportTypeKind::Pointee:
@@ -1283,14 +1283,29 @@ static ImportedType adjustTypeForConcreteImport(
1283
1283
}
1284
1284
1285
1285
// SwiftTypeConverter turns block pointers into @convention(block) types.
1286
- // In a bridgeable context, or in the direct structure of a typedef,
1287
- // we would prefer to instead use the default Swift convention.
1286
+ // In some contexts, we bridge them to use the Swift function type
1287
+ // representation. This includes typedefs of block types, which use the
1288
+ // Swift function type representation.
1288
1289
if (hint == ImportHint::Block) {
1289
1290
if (canBridgeTypes (importKind)) {
1291
+ // Determine the function type representation we need.
1292
+ //
1293
+ // For Objective-C collection arguments, we cannot bridge from a block
1294
+ // to a Swift function type, so force the block representation. Normally
1295
+ // the mapped type will have a block representation (making this a no-op),
1296
+ // but in cases where the Clang type was written as a typedef of a
1297
+ // block type, that typedef will have a Swift function type
1298
+ // representation. This code will then break down the imported type
1299
+ // alias and produce a function type with block representation.
1300
+ auto requiredFunctionTypeRepr = FunctionTypeRepresentation::Swift;
1301
+ if (importKind == ImportTypeKind::ObjCCollectionElement) {
1302
+ requiredFunctionTypeRepr = FunctionTypeRepresentation::Block;
1303
+ }
1304
+
1290
1305
auto fTy = importedType->castTo <FunctionType>();
1291
1306
FunctionType::ExtInfo einfo = fTy ->getExtInfo ();
1292
- if (einfo.getRepresentation () != FunctionTypeRepresentation::Swift ) {
1293
- einfo = einfo.withRepresentation (FunctionTypeRepresentation::Swift );
1307
+ if (einfo.getRepresentation () != requiredFunctionTypeRepr ) {
1308
+ einfo = einfo.withRepresentation (requiredFunctionTypeRepr );
1294
1309
importedType = fTy ->withExtInfo (einfo);
1295
1310
}
1296
1311
}
0 commit comments