@@ -2747,10 +2747,28 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
27472747 ImportDiagnosticAdder addImportDiag (*this , clangDecl,
27482748 clangDecl->getLocation ());
27492749 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);
27542772
27552773 // Adjust the result type for a throwing function.
27562774 if (importedType.getType () && errorInfo) {
@@ -2860,7 +2878,21 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
28602878 ImportTypeKind importKind = ImportTypeKind::Parameter;
28612879 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
28622880 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+
28642896 if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
28652897 paramTy->isObjCIdType ()) {
28662898 // Not using `getImportTypeAttrs()` is unprincipled but OK for this hack.
@@ -2872,7 +2904,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
28722904 swiftParamTy = OptionalType::get (swiftParamTy);
28732905
28742906 paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
2875- } else {
2907+ } else if (!swiftParamTy) {
28762908 if (param->hasAttr <clang::CFReturnsRetainedAttr>())
28772909 importKind = ImportTypeKind::CFRetainedOutParameter;
28782910 else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
0 commit comments