@@ -3595,11 +3595,30 @@ namespace {
35953595 return nullptr ;
35963596 }
35973597
3598- auto importedType =
3599- Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3600- ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3601- isInSystemModule (dc), Bridgeability::None,
3602- getImportTypeAttrs (decl));
3598+ ImportedType importedType;
3599+ auto fieldType = decl->getType ();
3600+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
3601+ fieldType = elaborated->desugar ();
3602+ if (auto typedefType = dyn_cast<clang::TypedefType>(fieldType)) {
3603+ if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
3604+ if (auto clangEnum = findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
3605+ // If this fails, it means that we need a stronger predicate for
3606+ // determining the relationship between an enum and typedef.
3607+ assert (clangEnum.value ()->getIntegerType ()->getCanonicalTypeInternal () ==
3608+ typedefType->getCanonicalTypeInternal ());
3609+ if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
3610+ importedType = {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType (), false };
3611+ }
3612+ }
3613+ }
3614+ }
3615+
3616+ if (!importedType)
3617+ importedType =
3618+ Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3619+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3620+ isInSystemModule (dc), Bridgeability::None,
3621+ getImportTypeAttrs (decl));
36033622 if (!importedType) {
36043623 Impl.addImportDiagnostic (
36053624 decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5828,6 +5847,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
58285847 const clang::EnumDecl *decl) {
58295848 ASTContext &ctx = Impl.SwiftContext ;
58305849
5850+ auto Loc = Impl.importSourceLoc (decl->getLocation ());
5851+
5852+ // Create a struct with the underlying type as a field.
5853+ auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5854+ decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5855+ Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = structDecl;
5856+
58315857 // Compute the underlying type.
58325858 auto underlyingType = Impl.importTypeIgnoreIUO (
58335859 decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5836,12 +5862,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
58365862 if (!underlyingType)
58375863 return nullptr ;
58385864
5839- auto Loc = Impl.importSourceLoc (decl->getLocation ());
5840-
5841- // Create a struct with the underlying type as a field.
5842- auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5843- decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5844-
58455865 synthesizer.makeStructRawValued (structDecl, underlyingType,
58465866 {KnownProtocolKind::OptionSet});
58475867 auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments