@@ -3570,11 +3570,30 @@ namespace {
3570
3570
return nullptr ;
3571
3571
}
3572
3572
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));
3578
3597
if (!importedType) {
3579
3598
Impl.addImportDiagnostic (
3580
3599
decl, Diagnostic (diag::record_field_not_imported, decl),
@@ -5797,6 +5816,13 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5797
5816
const clang::EnumDecl *decl) {
5798
5817
ASTContext &ctx = Impl.SwiftContext ;
5799
5818
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
+
5800
5826
// Compute the underlying type.
5801
5827
auto underlyingType = Impl.importTypeIgnoreIUO (
5802
5828
decl->getIntegerType (), ImportTypeKind::Enum,
@@ -5805,12 +5831,6 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
5805
5831
if (!underlyingType)
5806
5832
return nullptr ;
5807
5833
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
-
5814
5834
synthesizer.makeStructRawValued (structDecl, underlyingType,
5815
5835
{KnownProtocolKind::OptionSet});
5816
5836
auto selfType = structDecl->getDeclaredInterfaceType ();
0 commit comments