@@ -2086,18 +2086,22 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2086
2086
OptionalityOfReturn = OTK_ImplicitlyUnwrappedOptional;
2087
2087
}
2088
2088
2089
+ clang::QualType returnType = clangDecl->getReturnType ();
2090
+ if (auto elaborated =
2091
+ dyn_cast<clang::ElaboratedType>(returnType))
2092
+ returnType = elaborated->desugar ();
2093
+
2089
2094
// Specialized templates need to match the args/result exactly (i.e.,
2090
2095
// ptr -> ptr not ptr -> Optional<ptr>).
2091
- if (clangDecl->getReturnType ()->isPointerType () &&
2092
- clangDecl->getPrimaryTemplate () &&
2096
+ if (returnType->isPointerType () && clangDecl->getPrimaryTemplate () &&
2093
2097
clangDecl
2094
2098
->getPrimaryTemplate ()
2095
2099
->getAsFunction ()
2096
2100
->getReturnType ()
2097
2101
->isTemplateTypeParmType ())
2098
2102
OptionalityOfReturn = OTK_None;
2099
2103
2100
- if (auto typedefType = dyn_cast<clang::TypedefType>(clangDecl-> getReturnType (). getTypePtr () )) {
2104
+ if (auto typedefType = dyn_cast<clang::TypedefType>(returnType )) {
2101
2105
if (isUnavailableInSwift (typedefType->getDecl ())) {
2102
2106
if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
2103
2107
// If this fails, it means that we need a stronger predicate for
@@ -2112,7 +2116,7 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
2112
2116
}
2113
2117
2114
2118
// Import the result type.
2115
- return importType (clangDecl-> getReturnType () ,
2119
+ return importType (returnType ,
2116
2120
(isAuditedResult ? ImportTypeKind::AuditedResult
2117
2121
: ImportTypeKind::Result),
2118
2122
ImportDiagnosticAdder (*this , clangDecl,
@@ -2159,7 +2163,11 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2159
2163
ImportedType importedType;
2160
2164
ImportDiagnosticAdder addDiag (*this , clangDecl,
2161
2165
clangDecl->getSourceRange ().getBegin ());
2162
- if (auto typedefType = dyn_cast<clang::TypedefType>(clangDecl->getReturnType ().getTypePtr ())) {
2166
+ clang::QualType returnType = clangDecl->getReturnType ();
2167
+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(returnType))
2168
+ returnType = elaborated->desugar ();
2169
+
2170
+ if (auto typedefType = dyn_cast<clang::TypedefType>(returnType)) {
2163
2171
if (isUnavailableInSwift (typedefType->getDecl ())) {
2164
2172
if (auto clangEnum = findAnonymousEnumForTypedef (SwiftContext, typedefType)) {
2165
2173
// If this fails, it means that we need a stronger predicate for
@@ -2174,15 +2182,15 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2174
2182
}
2175
2183
2176
2184
if (auto templateType =
2177
- dyn_cast<clang::TemplateTypeParmType>(clangDecl-> getReturnType () )) {
2185
+ dyn_cast<clang::TemplateTypeParmType>(returnType )) {
2178
2186
importedType = {findGenericTypeInGenericDecls (
2179
2187
*this , templateType, genericParams,
2180
2188
getImportTypeAttrs (clangDecl), addDiag),
2181
2189
false };
2182
- } else if ((isa<clang::PointerType>(clangDecl-> getReturnType () ) ||
2183
- isa<clang::ReferenceType>(clangDecl-> getReturnType () )) &&
2184
- isa<clang::TemplateTypeParmType>(clangDecl-> getReturnType () ->getPointeeType ())) {
2185
- auto pointeeType = clangDecl-> getReturnType () ->getPointeeType ();
2190
+ } else if ((isa<clang::PointerType>(returnType ) ||
2191
+ isa<clang::ReferenceType>(returnType )) &&
2192
+ isa<clang::TemplateTypeParmType>(returnType ->getPointeeType ())) {
2193
+ auto pointeeType = returnType ->getPointeeType ();
2186
2194
auto templateParamType = cast<clang::TemplateTypeParmType>(pointeeType);
2187
2195
PointerTypeKind pointerKind = pointeeType.getQualifiers ().hasConst ()
2188
2196
? PTK_UnsafePointer
@@ -2191,13 +2199,13 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2191
2199
findGenericTypeInGenericDecls (*this , templateParamType, genericParams,
2192
2200
getImportTypeAttrs (clangDecl), addDiag);
2193
2201
importedType = {genericType->wrapInPointer (pointerKind), false };
2194
- } else if (!(isa<clang::RecordType>(clangDecl-> getReturnType () ) ||
2195
- isa<clang::TemplateSpecializationType>(clangDecl-> getReturnType () )) ||
2202
+ } else if (!(isa<clang::RecordType>(returnType ) ||
2203
+ isa<clang::TemplateSpecializationType>(returnType )) ||
2196
2204
// TODO: we currently don't lazily load operator return types, but
2197
2205
// this should be trivial to add.
2198
2206
clangDecl->isOverloadedOperator () ||
2199
2207
// Dependant types are trivially mapped as Any.
2200
- clangDecl-> getReturnType () ->isDependentType ()) {
2208
+ returnType ->isDependentType ()) {
2201
2209
// If importedType is already initialized, it means we found the enum that
2202
2210
// was supposed to be used (instead of the typedef type).
2203
2211
if (!importedType) {
@@ -2244,6 +2252,8 @@ ClangImporter::Implementation::importParameterType(
2244
2252
ArrayRef<GenericTypeParamDecl *> genericParams,
2245
2253
llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
2246
2254
auto paramTy = param->getType ();
2255
+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(paramTy))
2256
+ paramTy = elaborated->desugar ();
2247
2257
2248
2258
ImportTypeKind importKind = getImportTypeKindForParam (param);
2249
2259
@@ -2845,7 +2855,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2845
2855
ImportDiagnosticAdder addImportDiag (*this , clangDecl,
2846
2856
clangDecl->getLocation ());
2847
2857
clang::QualType resultType = clangDecl->getReturnType ();
2848
-
2858
+ if (auto elaborated = dyn_cast<clang::ElaboratedType>(resultType))
2859
+ resultType = elaborated->desugar ();
2849
2860
2850
2861
ImportedType importedType;
2851
2862
if (auto typedefType = dyn_cast<clang::TypedefType>(resultType.getTypePtr ())) {
0 commit comments