@@ -816,6 +816,31 @@ static bool isPrintLikeMethod(DeclName name, const DeclContext *dc) {
816
816
using MirroredMethodEntry =
817
817
std::tuple<const clang::ObjCMethodDecl*, ProtocolDecl*, bool /* isAsync*/ >;
818
818
819
+ ImportedType tryImportOptionsTypeForField (const clang::QualType type,
820
+ ClangImporter::Implementation &Impl) {
821
+ ImportedType importedType;
822
+ auto fieldType = type;
823
+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
824
+ fieldType = elaborated->desugar ();
825
+ if (auto typedefType = dyn_cast<clang::TypedefType>(fieldType)) {
826
+ if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
827
+ if (auto clangEnum =
828
+ findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
829
+ // If this fails, it means that we need a stronger predicate for
830
+ // determining the relationship between an enum and typedef.
831
+ assert (
832
+ clangEnum.value ()->getIntegerType ()->getCanonicalTypeInternal () ==
833
+ typedefType->getCanonicalTypeInternal ());
834
+ if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
835
+ importedType = {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType (),
836
+ false };
837
+ }
838
+ }
839
+ }
840
+ }
841
+ return importedType;
842
+ }
843
+
819
844
namespace {
820
845
// / Customized llvm::DenseMapInfo for storing borrowed APSInts.
821
846
struct APSIntRefDenseMapInfo {
@@ -3663,23 +3688,8 @@ namespace {
3663
3688
return nullptr ;
3664
3689
}
3665
3690
3666
- ImportedType importedType;
3667
3691
auto fieldType = decl->getType ();
3668
- if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
3669
- fieldType = elaborated->desugar ();
3670
- if (auto typedefType = dyn_cast<clang::TypedefType>(fieldType)) {
3671
- if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
3672
- if (auto clangEnum = findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
3673
- // If this fails, it means that we need a stronger predicate for
3674
- // determining the relationship between an enum and typedef.
3675
- assert (clangEnum.value ()->getIntegerType ()->getCanonicalTypeInternal () ==
3676
- typedefType->getCanonicalTypeInternal ());
3677
- if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
3678
- importedType = {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType (), false };
3679
- }
3680
- }
3681
- }
3682
- }
3692
+ ImportedType importedType = tryImportOptionsTypeForField (fieldType, Impl);
3683
3693
3684
3694
if (!importedType)
3685
3695
importedType =
@@ -5201,7 +5211,11 @@ namespace {
5201
5211
}
5202
5212
}
5203
5213
5204
- auto importedType = Impl.importPropertyType (decl, isInSystemModule (dc));
5214
+ auto fieldType = decl->getType ();
5215
+ ImportedType importedType = tryImportOptionsTypeForField (fieldType, Impl);
5216
+
5217
+ if (!importedType)
5218
+ importedType = Impl.importPropertyType (decl, isInSystemModule (dc));
5205
5219
if (!importedType) {
5206
5220
Impl.addImportDiagnostic (
5207
5221
decl, Diagnostic (diag::objc_property_not_imported, decl),
0 commit comments