@@ -3595,11 +3595,30 @@ namespace {
3595
3595
return nullptr ;
3596
3596
}
3597
3597
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));
3603
3622
if (!importedType) {
3604
3623
Impl.addImportDiagnostic (
3605
3624
decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5828,6 +5847,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5828
5847
const clang::EnumDecl *decl) {
5829
5848
ASTContext &ctx = Impl.SwiftContext ;
5830
5849
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
+
5831
5857
// Compute the underlying type.
5832
5858
auto underlyingType = Impl.importTypeIgnoreIUO (
5833
5859
decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5836,12 +5862,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5836
5862
if (!underlyingType)
5837
5863
return nullptr ;
5838
5864
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
-
5845
5865
synthesizer.makeStructRawValued (structDecl, underlyingType,
5846
5866
{KnownProtocolKind::OptionSet});
5847
5867
auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments