@@ -3570,11 +3570,30 @@ namespace {
35703570 return nullptr ;
35713571 }
35723572
3573- auto importedType =
3574- Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3575- ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3576- isInSystemModule (dc), Bridgeability::None,
3577- getImportTypeAttrs (decl));
3573+ ImportedType importedType;
3574+ auto fieldType = decl->getType ();
3575+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
3576+ fieldType = elaborated->desugar ();
3577+ if (auto typedefType = dyn_cast<clang::TypedefType>(fieldType)) {
3578+ if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
3579+ if (auto clangEnum = findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
3580+ // If this fails, it means that we need a stronger predicate for
3581+ // determining the relationship between an enum and typedef.
3582+ assert (clangEnum.value ()->getIntegerType ()->getCanonicalTypeInternal () ==
3583+ typedefType->getCanonicalTypeInternal ());
3584+ if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
3585+ importedType = {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType (), false };
3586+ }
3587+ }
3588+ }
3589+ }
3590+
3591+ if (!importedType)
3592+ importedType =
3593+ Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3594+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3595+ isInSystemModule (dc), Bridgeability::None,
3596+ getImportTypeAttrs (decl));
35783597 if (!importedType) {
35793598 Impl.addImportDiagnostic (
35803599 decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5797,6 +5816,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
57975816 const clang::EnumDecl *decl) {
57985817 ASTContext &ctx = Impl.SwiftContext ;
57995818
5819+ auto Loc = Impl.importSourceLoc (decl->getLocation ());
5820+
5821+ // Create a struct with the underlying type as a field.
5822+ auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5823+ decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5824+ Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = structDecl;
5825+
58005826 // Compute the underlying type.
58015827 auto underlyingType = Impl.importTypeIgnoreIUO (
58025828 decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5805,12 +5831,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
58055831 if (!underlyingType)
58065832 return nullptr ;
58075833
5808- auto Loc = Impl.importSourceLoc (decl->getLocation ());
5809-
5810- // Create a struct with the underlying type as a field.
5811- auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5812- decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5813-
58145834 synthesizer.makeStructRawValued (structDecl, underlyingType,
58155835 {KnownProtocolKind::OptionSet});
58165836 auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments