@@ -3585,11 +3585,30 @@ namespace {
35853585 return nullptr ;
35863586 }
35873587
3588- auto importedType =
3589- Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3590- ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3591- isInSystemModule (dc), Bridgeability::None,
3592- getImportTypeAttrs (decl));
3588+ ImportedType importedType;
3589+ auto fieldType = decl->getType ();
3590+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
3591+ fieldType = elaborated->desugar ();
3592+ if (auto typedefType = dyn_cast<clang::TypedefType>(fieldType)) {
3593+ if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
3594+ if (auto clangEnum = findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
3595+ // If this fails, it means that we need a stronger predicate for
3596+ // determining the relationship between an enum and typedef.
3597+ assert (clangEnum.value ()->getIntegerType ()->getCanonicalTypeInternal () ==
3598+ typedefType->getCanonicalTypeInternal ());
3599+ if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
3600+ importedType = {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType (), false };
3601+ }
3602+ }
3603+ }
3604+ }
3605+
3606+ if (!importedType)
3607+ importedType =
3608+ Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3609+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3610+ isInSystemModule (dc), Bridgeability::None,
3611+ getImportTypeAttrs (decl));
35933612 if (!importedType) {
35943613 Impl.addImportDiagnostic (
35953614 decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5818,6 +5837,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
58185837 const clang::EnumDecl *decl) {
58195838 ASTContext &ctx = Impl.SwiftContext ;
58205839
5840+ auto Loc = Impl.importSourceLoc (decl->getLocation ());
5841+
5842+ // Create a struct with the underlying type as a field.
5843+ auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5844+ decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5845+ Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = structDecl;
5846+
58215847 // Compute the underlying type.
58225848 auto underlyingType = Impl.importTypeIgnoreIUO (
58235849 decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5826,12 +5852,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
58265852 if (!underlyingType)
58275853 return nullptr ;
58285854
5829- auto Loc = Impl.importSourceLoc (decl->getLocation ());
5830-
5831- // Create a struct with the underlying type as a field.
5832- auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5833- decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5834-
58355855 synthesizer.makeStructRawValued (structDecl, underlyingType,
58365856 {KnownProtocolKind::OptionSet});
58375857 auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments