@@ -2734,10 +2734,28 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
27342734 ImportDiagnosticAdder addImportDiag (*this , clangDecl,
27352735 clangDecl->getLocation ());
27362736 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);
27412759
27422760 // Adjust the result type for a throwing function.
27432761 if (importedType.getType () && errorInfo) {
@@ -2847,7 +2865,21 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
28472865 ImportTypeKind importKind = ImportTypeKind::Parameter;
28482866 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
28492867 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+
28512883 if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
28522884 paramTy->isObjCIdType ()) {
28532885 // Not using `getImportTypeAttrs()` is unprincipled but OK for this hack.
@@ -2859,7 +2891,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
28592891 swiftParamTy = OptionalType::get (swiftParamTy);
28602892
28612893 paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
2862- } else {
2894+ } else if (!swiftParamTy) {
28632895 if (param->hasAttr <clang::CFReturnsRetainedAttr>())
28642896 importKind = ImportTypeKind::CFRetainedOutParameter;
28652897 else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
0 commit comments