@@ -2230,6 +2230,17 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2230
2230
return {swiftResultTy, importedType.isImplicitlyUnwrapped ()};
2231
2231
}
2232
2232
2233
+ static ImportTypeKind
2234
+ getImportTypeKindForParam (const clang::ParmVarDecl *param) {
2235
+ ImportTypeKind importKind = ImportTypeKind::Parameter;
2236
+ if (param->hasAttr <clang::CFReturnsRetainedAttr>())
2237
+ importKind = ImportTypeKind::CFRetainedOutParameter;
2238
+ else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
2239
+ importKind = ImportTypeKind::CFUnretainedOutParameter;
2240
+
2241
+ return importKind;
2242
+ }
2243
+
2233
2244
ParameterList *ClangImporter::Implementation::importFunctionParameterList (
2234
2245
DeclContext *dc, const clang::FunctionDecl *clangDecl,
2235
2246
ArrayRef<const clang::ParmVarDecl *> params, bool isVariadic,
@@ -2254,11 +2265,7 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
2254
2265
// Check nullability of the parameter.
2255
2266
OptionalTypeKind OptionalityOfParam = getParamOptionality (param, knownNonNull);
2256
2267
2257
- ImportTypeKind importKind = ImportTypeKind::Parameter;
2258
- if (param->hasAttr <clang::CFReturnsRetainedAttr>())
2259
- importKind = ImportTypeKind::CFRetainedOutParameter;
2260
- else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
2261
- importKind = ImportTypeKind::CFUnretainedOutParameter;
2268
+ ImportTypeKind importKind = getImportTypeKindForParam (param);
2262
2269
2263
2270
// Import the parameter type into Swift.
2264
2271
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
@@ -2904,7 +2911,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2904
2911
}
2905
2912
2906
2913
// Special case for NSDictionary's subscript.
2907
- ImportTypeKind importKind = ImportTypeKind::Parameter ;
2914
+ ImportTypeKind importKind = getImportTypeKindForParam (param) ;
2908
2915
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
2909
2916
Type swiftParamTy;
2910
2917
bool paramIsIUO = false ;
@@ -2934,11 +2941,6 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2934
2941
2935
2942
paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
2936
2943
} else if (!swiftParamTy) {
2937
- if (param->hasAttr <clang::CFReturnsRetainedAttr>())
2938
- importKind = ImportTypeKind::CFRetainedOutParameter;
2939
- else if (param->hasAttr <clang::CFReturnsNotRetainedAttr>())
2940
- importKind = ImportTypeKind::CFUnretainedOutParameter;
2941
-
2942
2944
// Figure out if this is a completion handler parameter whose error
2943
2945
// parameter is used to indicate throwing.
2944
2946
Optional<unsigned > completionHandlerErrorParamIndex;
0 commit comments