@@ -1020,7 +1020,7 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
1020
1020
case ImportTypeKind::CFRetainedOutParameter:
1021
1021
case ImportTypeKind::CFUnretainedOutParameter:
1022
1022
case ImportTypeKind::Property:
1023
- case ImportTypeKind::PropertyAccessor :
1023
+ case ImportTypeKind::PropertyWithReferenceSemantics :
1024
1024
case ImportTypeKind::BridgedValue:
1025
1025
return true ;
1026
1026
}
@@ -1045,7 +1045,7 @@ static bool isCFAudited(ImportTypeKind importKind) {
1045
1045
case ImportTypeKind::CFRetainedOutParameter:
1046
1046
case ImportTypeKind::CFUnretainedOutParameter:
1047
1047
case ImportTypeKind::Property:
1048
- case ImportTypeKind::PropertyAccessor :
1048
+ case ImportTypeKind::PropertyWithReferenceSemantics :
1049
1049
return true ;
1050
1050
}
1051
1051
}
@@ -1091,8 +1091,7 @@ static Type adjustTypeForConcreteImport(ClangImporter::Implementation &impl,
1091
1091
// 'void' can only be imported as a function result type.
1092
1092
if (hint == ImportHint::Void &&
1093
1093
(importKind == ImportTypeKind::AuditedResult ||
1094
- importKind == ImportTypeKind::Result ||
1095
- importKind == ImportTypeKind::PropertyAccessor)) {
1094
+ importKind == ImportTypeKind::Result)) {
1096
1095
return impl.getNamedSwiftType (impl.getStdlibModule (), " Void" );
1097
1096
}
1098
1097
@@ -1268,13 +1267,16 @@ static Type adjustTypeForConcreteImport(ClangImporter::Implementation &impl,
1268
1267
1269
1268
// If we have a bridged Objective-C type and we are allowed to
1270
1269
// bridge, do so.
1271
- if (hint == ImportHint::ObjCBridged && canBridgeTypes (importKind))
1270
+ if (hint == ImportHint::ObjCBridged && canBridgeTypes (importKind) &&
1271
+ importKind != ImportTypeKind::PropertyWithReferenceSemantics) {
1272
1272
// id and Any can be bridged without Foundation. There would be
1273
1273
// bootstrapping issues with the ObjectiveC module otherwise.
1274
1274
if (hint.BridgedType ->isAny ()
1275
1275
|| impl.tryLoadFoundationModule ()
1276
- || impl.ImportForwardDeclarations )
1276
+ || impl.ImportForwardDeclarations ) {
1277
1277
importedType = hint.BridgedType ;
1278
+ }
1279
+ }
1278
1280
1279
1281
if (!importedType)
1280
1282
return importedType;
@@ -1399,8 +1401,38 @@ bool ClangImporter::Implementation::shouldAllowNSUIntegerAsInt(
1399
1401
Type ClangImporter::Implementation::importPropertyType (
1400
1402
const clang::ObjCPropertyDecl *decl,
1401
1403
bool isFromSystemModule) {
1404
+ const auto assignOrUnsafeUnretained =
1405
+ clang::ObjCPropertyDecl::OBJC_PR_assign |
1406
+ clang::ObjCPropertyDecl::OBJC_PR_unsafe_unretained;
1407
+
1408
+ ImportTypeKind importKind;
1409
+ // HACK: Accessibility decls are always imported using bridged types,
1410
+ // because they're inconsistent between properties and methods.
1411
+ if (isAccessibilityDecl (decl)) {
1412
+ importKind = ImportTypeKind::Property;
1413
+ } else {
1414
+ switch (decl->getSetterKind ()) {
1415
+ case clang::ObjCPropertyDecl::Assign:
1416
+ // If it's readonly, this might just be returned as a default.
1417
+ if (decl->isReadOnly () &&
1418
+ (decl->getPropertyAttributes () & assignOrUnsafeUnretained) == 0 ) {
1419
+ importKind = ImportTypeKind::Property;
1420
+ } else {
1421
+ importKind = ImportTypeKind::PropertyWithReferenceSemantics;
1422
+ }
1423
+ break ;
1424
+ case clang::ObjCPropertyDecl::Retain:
1425
+ case clang::ObjCPropertyDecl::Copy:
1426
+ importKind = ImportTypeKind::Property;
1427
+ break ;
1428
+ case clang::ObjCPropertyDecl::Weak:
1429
+ importKind = ImportTypeKind::PropertyWithReferenceSemantics;
1430
+ break ;
1431
+ }
1432
+ }
1433
+
1402
1434
OptionalTypeKind optionality = OTK_ImplicitlyUnwrappedOptional;
1403
- return importType (decl->getType (), ImportTypeKind::Property ,
1435
+ return importType (decl->getType (), importKind ,
1404
1436
shouldAllowNSUIntegerAsInt (isFromSystemModule, decl),
1405
1437
/* isFullyBridgeable*/ true , optionality);
1406
1438
}
@@ -2173,9 +2205,7 @@ Type ClangImporter::Implementation::importMethodType(
2173
2205
// returning CF types as a workaround for ARC not managing CF
2174
2206
// objects
2175
2207
ImportTypeKind resultKind;
2176
- if (kind == SpecialMethodKind::PropertyAccessor)
2177
- resultKind = ImportTypeKind::PropertyAccessor;
2178
- else if (isObjCMethodResultAudited (clangDecl))
2208
+ if (isObjCMethodResultAudited (clangDecl))
2179
2209
resultKind = ImportTypeKind::AuditedResult;
2180
2210
else
2181
2211
resultKind = ImportTypeKind::Result;
@@ -2335,12 +2365,6 @@ Type ClangImporter::Implementation::importMethodType(
2335
2365
swiftParamTy = getOptionalType (getNSCopyingType (),
2336
2366
ImportTypeKind::Parameter,
2337
2367
optionalityOfParam);
2338
- } else if (kind == SpecialMethodKind::PropertyAccessor) {
2339
- swiftParamTy = importType (paramTy,
2340
- ImportTypeKind::PropertyAccessor,
2341
- allowNSUIntegerAsIntInParam,
2342
- /* isFullyBridgeable*/ true ,
2343
- optionalityOfParam);
2344
2368
} else {
2345
2369
ImportTypeKind importKind = ImportTypeKind::Parameter;
2346
2370
if (param->hasAttr <clang::CFReturnsRetainedAttr>())
0 commit comments