@@ -2734,10 +2734,28 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2734
2734
ImportDiagnosticAdder addImportDiag (*this , clangDecl,
2735
2735
clangDecl->getLocation ());
2736
2736
clang::QualType resultType = clangDecl->getReturnType ();
2737
- auto importedType =
2738
- importType (resultType, resultKind, addImportDiag,
2739
- allowNSUIntegerAsIntInResult, Bridgeability::Full,
2740
- getImportTypeAttrs (clangDecl), OptionalityOfReturn);
2737
+
2738
+
2739
+ ImportedType importedType;
2740
+ if (auto typedefType = dyn_cast<clang::TypedefType>(resultType.getTypePtr ())) {
2741
+ if (isUnavailableInSwift (typedefType->getDecl ())) {
2742
+ if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
2743
+ // If this fails, it means that we need a stronger predicate for
2744
+ // determining the relationship between an enum and typedef.
2745
+ assert (clangEnum.getValue ()->getIntegerType ()->getCanonicalTypeInternal () ==
2746
+ typedefType->getCanonicalTypeInternal ());
2747
+ if (auto swiftEnum = importDecl (*clangEnum, CurrentVersion)) {
2748
+ importedType = {cast<NominalTypeDecl>(swiftEnum)->getDeclaredType (), false };
2749
+ }
2750
+ }
2751
+ }
2752
+ }
2753
+
2754
+ if (!importedType)
2755
+ importedType = importType (resultType, resultKind, addImportDiag,
2756
+ allowNSUIntegerAsIntInResult, Bridgeability::Full,
2757
+ getImportTypeAttrs (clangDecl),
2758
+ OptionalityOfReturn);
2741
2759
2742
2760
// Adjust the result type for a throwing function.
2743
2761
if (importedType.getType () && errorInfo) {
@@ -2847,7 +2865,21 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2847
2865
ImportTypeKind importKind = ImportTypeKind::Parameter;
2848
2866
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
2849
2867
Type swiftParamTy;
2850
- bool paramIsIUO;
2868
+ bool paramIsIUO = false ;
2869
+ if (auto typedefType = dyn_cast<clang::TypedefType>(paramTy.getTypePtr ())) {
2870
+ if (isUnavailableInSwift (typedefType->getDecl ())) {
2871
+ if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
2872
+ // If this fails, it means that we need a stronger predicate for
2873
+ // determining the relationship between an enum and typedef.
2874
+ assert (clangEnum.getValue ()->getIntegerType ()->getCanonicalTypeInternal () ==
2875
+ typedefType->getCanonicalTypeInternal ());
2876
+ if (auto swiftEnum = importDecl (*clangEnum, CurrentVersion)) {
2877
+ swiftParamTy = cast<NominalTypeDecl>(swiftEnum)->getDeclaredType ();
2878
+ }
2879
+ }
2880
+ }
2881
+ }
2882
+
2851
2883
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
2852
2884
paramTy->isObjCIdType ()) {
2853
2885
// Not using `getImportTypeAttrs()` is unprincipled but OK for this hack.
@@ -2859,7 +2891,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2859
2891
swiftParamTy = OptionalType::get (swiftParamTy);
2860
2892
2861
2893
paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
2862
- } else {
2894
+ } else if (!swiftParamTy) {
2863
2895
if (param->hasAttr <clang::CFReturnsRetainedAttr>())
2864
2896
importKind = ImportTypeKind::CFRetainedOutParameter;
2865
2897
else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
0 commit comments