@@ -3585,11 +3585,30 @@ namespace {
3585
3585
return nullptr ;
3586
3586
}
3587
3587
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));
3593
3612
if (!importedType) {
3594
3613
Impl.addImportDiagnostic (
3595
3614
decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5818,6 +5837,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5818
5837
const clang::EnumDecl *decl) {
5819
5838
ASTContext &ctx = Impl.SwiftContext ;
5820
5839
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
+
5821
5847
// Compute the underlying type.
5822
5848
auto underlyingType = Impl.importTypeIgnoreIUO (
5823
5849
decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5826,12 +5852,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5826
5852
if (!underlyingType)
5827
5853
return nullptr ;
5828
5854
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
-
5835
5855
synthesizer.makeStructRawValued (structDecl, underlyingType,
5836
5856
{KnownProtocolKind::OptionSet});
5837
5857
auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments