@@ -5706,14 +5706,35 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
57065706 if (dc->isTypeContext () && !getterName.getSelfIndex ())
57075707 isStatic = true ;
57085708
5709- // Compute the property type.
5710- bool isFromSystemModule = isInSystemModule (dc);
5711- auto importedType = Impl.importType (
5712- propertyType, ImportTypeKind::Property,
5713- ImportDiagnosticAdder (Impl, getter, getter->getLocation ()),
5714- Impl.shouldAllowNSUIntegerAsInt (isFromSystemModule, getter),
5715- Bridgeability::Full, getImportTypeAttrs (accessor),
5716- OTK_ImplicitlyUnwrappedOptional);
5709+ ImportedType importedType;
5710+
5711+ // Sometimes we import unavailable typedefs as enums. If that's the case,
5712+ // use the enum, not the typedef here.
5713+ if (auto typedefType = dyn_cast<clang::TypedefType>(propertyType.getTypePtr ())) {
5714+ if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
5715+ if (auto clangEnum = findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
5716+ // If this fails, it means that we need a stronger predicate for
5717+ // determining the relationship between an enum and typedef.
5718+ assert (clangEnum.getValue ()->getIntegerType ()->getCanonicalTypeInternal () ==
5719+ typedefType->getCanonicalTypeInternal ());
5720+ if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
5721+ importedType = {cast<NominalTypeDecl>(swiftEnum)->getDeclaredType (), false };
5722+ }
5723+ }
5724+ }
5725+ }
5726+
5727+ if (!importedType) {
5728+ // Compute the property type.
5729+ bool isFromSystemModule = isInSystemModule (dc);
5730+ importedType = Impl.importType (
5731+ propertyType, ImportTypeKind::Property,
5732+ ImportDiagnosticAdder (Impl, getter, getter->getLocation ()),
5733+ Impl.shouldAllowNSUIntegerAsInt (isFromSystemModule, getter),
5734+ Bridgeability::Full, getImportTypeAttrs (accessor),
5735+ OTK_ImplicitlyUnwrappedOptional);
5736+ }
5737+
57175738 if (!importedType)
57185739 return nullptr ;
57195740
0 commit comments