@@ -3584,11 +3584,30 @@ namespace {
3584
3584
return nullptr ;
3585
3585
}
3586
3586
3587
- auto importedType =
3588
- Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3589
- ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3590
- isInSystemModule (dc), Bridgeability::None,
3591
- getImportTypeAttrs (decl));
3587
+ ImportedType importedType;
3588
+ auto fieldType = decl->getType ();
3589
+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(fieldType))
3590
+ fieldType = elaborated->desugar ();
3591
+ if (auto typedefType = dyn_cast<clang::TypedefType>(fieldType)) {
3592
+ if (Impl.isUnavailableInSwift (typedefType->getDecl ())) {
3593
+ if (auto clangEnum = findAnonymousEnumForTypedef (Impl.SwiftContext , typedefType)) {
3594
+ // If this fails, it means that we need a stronger predicate for
3595
+ // determining the relationship between an enum and typedef.
3596
+ assert (clangEnum.value ()->getIntegerType ()->getCanonicalTypeInternal () ==
3597
+ typedefType->getCanonicalTypeInternal ());
3598
+ if (auto swiftEnum = Impl.importDecl (*clangEnum, Impl.CurrentVersion )) {
3599
+ importedType = {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType (), false };
3600
+ }
3601
+ }
3602
+ }
3603
+ }
3604
+
3605
+ if (!importedType)
3606
+ importedType =
3607
+ Impl.importType (decl->getType (), ImportTypeKind::RecordField,
3608
+ ImportDiagnosticAdder (Impl, decl, decl->getLocation ()),
3609
+ isInSystemModule (dc), Bridgeability::None,
3610
+ getImportTypeAttrs (decl));
3592
3611
if (!importedType) {
3593
3612
Impl.addImportDiagnostic (
3594
3613
decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5817,6 +5836,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5817
5836
const clang::EnumDecl *decl) {
5818
5837
ASTContext &ctx = Impl.SwiftContext ;
5819
5838
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
+ Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = structDecl;
5845
+
5820
5846
// Compute the underlying type.
5821
5847
auto underlyingType = Impl.importTypeIgnoreIUO (
5822
5848
decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5825,12 +5851,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5825
5851
if (!underlyingType)
5826
5852
return nullptr ;
5827
5853
5828
- auto Loc = Impl.importSourceLoc (decl->getLocation ());
5829
-
5830
- // Create a struct with the underlying type as a field.
5831
- auto structDecl = Impl.createDeclWithClangNode <StructDecl>(
5832
- decl, AccessLevel::Public, Loc, name, Loc, None, nullptr , dc);
5833
-
5834
5854
synthesizer.makeStructRawValued (structDecl, underlyingType,
5835
5855
{KnownProtocolKind::OptionSet});
5836
5856
auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments