@@ -2747,10 +2747,28 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2747
2747
ImportDiagnosticAdder addImportDiag (*this , clangDecl,
2748
2748
clangDecl->getLocation ());
2749
2749
clang::QualType resultType = clangDecl->getReturnType ();
2750
- auto importedType =
2751
- importType (resultType, resultKind, addImportDiag,
2752
- allowNSUIntegerAsIntInResult, Bridgeability::Full,
2753
- getImportTypeAttrs (clangDecl), OptionalityOfReturn);
2750
+
2751
+
2752
+ ImportedType importedType;
2753
+ if (auto typedefType = dyn_cast<clang::TypedefType>(resultType.getTypePtr ())) {
2754
+ if (isUnavailableInSwift (typedefType->getDecl ())) {
2755
+ if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
2756
+ // If this fails, it means that we need a stronger predicate for
2757
+ // determining the relationship between an enum and typedef.
2758
+ assert (clangEnum.getValue ()->getIntegerType ()->getCanonicalTypeInternal () ==
2759
+ typedefType->getCanonicalTypeInternal ());
2760
+ if (auto swiftEnum = importDecl (*clangEnum, CurrentVersion)) {
2761
+ importedType = {cast<NominalTypeDecl>(swiftEnum)->getDeclaredType (), false };
2762
+ }
2763
+ }
2764
+ }
2765
+ }
2766
+
2767
+ if (!importedType)
2768
+ importedType = importType (resultType, resultKind, addImportDiag,
2769
+ allowNSUIntegerAsIntInResult, Bridgeability::Full,
2770
+ getImportTypeAttrs (clangDecl),
2771
+ OptionalityOfReturn);
2754
2772
2755
2773
// Adjust the result type for a throwing function.
2756
2774
if (importedType.getType () && errorInfo) {
@@ -2860,7 +2878,21 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2860
2878
ImportTypeKind importKind = ImportTypeKind::Parameter;
2861
2879
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
2862
2880
Type swiftParamTy;
2863
- bool paramIsIUO;
2881
+ bool paramIsIUO = false ;
2882
+ if (auto typedefType = dyn_cast<clang::TypedefType>(paramTy.getTypePtr ())) {
2883
+ if (isUnavailableInSwift (typedefType->getDecl ())) {
2884
+ if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
2885
+ // If this fails, it means that we need a stronger predicate for
2886
+ // determining the relationship between an enum and typedef.
2887
+ assert (clangEnum.getValue ()->getIntegerType ()->getCanonicalTypeInternal () ==
2888
+ typedefType->getCanonicalTypeInternal ());
2889
+ if (auto swiftEnum = importDecl (*clangEnum, CurrentVersion)) {
2890
+ swiftParamTy = cast<NominalTypeDecl>(swiftEnum)->getDeclaredType ();
2891
+ }
2892
+ }
2893
+ }
2894
+ }
2895
+
2864
2896
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
2865
2897
paramTy->isObjCIdType ()) {
2866
2898
// Not using `getImportTypeAttrs()` is unprincipled but OK for this hack.
@@ -2872,7 +2904,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2872
2904
swiftParamTy = OptionalType::get (swiftParamTy);
2873
2905
2874
2906
paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
2875
- } else {
2907
+ } else if (!swiftParamTy) {
2876
2908
if (param->hasAttr <clang::CFReturnsRetainedAttr>())
2877
2909
importKind = ImportTypeKind::CFRetainedOutParameter;
2878
2910
else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
0 commit comments