@@ -2616,12 +2616,11 @@ bool ClangImporter::Implementation::isDefaultArgSafeToImport(
2616
2616
return true ;
2617
2617
}
2618
2618
2619
- static ParamDecl *getParameterInfo (ClangImporter::Implementation *impl,
2620
- const clang::ParmVarDecl *param,
2621
- const Identifier &name,
2622
- const swift::Type &swiftParamTy,
2623
- const bool isInOut,
2624
- const bool isParamTypeImplicitlyUnwrapped) {
2619
+ static std::optional<ParamDecl *>
2620
+ getParameterInfo (ClangImporter::Implementation *impl,
2621
+ const clang::ParmVarDecl *param, const Identifier &name,
2622
+ const swift::Type &swiftParamTy, const bool isInOut,
2623
+ const bool isParamTypeImplicitlyUnwrapped) {
2625
2624
// Figure out the name for this parameter.
2626
2625
Identifier bodyName = impl->importFullName (param, impl->CurrentVersion )
2627
2626
.getBaseIdentifier (impl->SwiftContext );
@@ -2657,9 +2656,11 @@ static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl,
2657
2656
// Swift doesn't support default values of inout parameters.
2658
2657
// TODO: support default arguments of constructors
2659
2658
// (https://github.com/apple/swift/issues/70124)
2659
+ // TODO: support params with template parameters
2660
2660
if (param->hasDefaultArg () && !isInOut &&
2661
2661
!isa<clang::CXXConstructorDecl>(param->getDeclContext ()) &&
2662
- impl->isDefaultArgSafeToImport (param)) {
2662
+ impl->isDefaultArgSafeToImport (param) &&
2663
+ !isa<clang::FunctionTemplateDecl>(param->getDeclContext ())) {
2663
2664
SwiftDeclSynthesizer synthesizer (*impl);
2664
2665
if (CallExpr *defaultArgExpr = synthesizer.makeDefaultArgument (
2665
2666
param, swiftParamTy, paramInfo->getParameterNameLoc ())) {
@@ -2724,7 +2725,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
2724
2725
2725
2726
auto paramInfo = getParameterInfo (this , param, name, swiftParamTy, isInOut,
2726
2727
isParamTypeImplicitlyUnwrapped);
2727
- parameters.push_back (paramInfo);
2728
+ if (!paramInfo.has_value ()) {
2729
+ addImportDiagnostic (param,
2730
+ Diagnostic (diag::parameter_type_not_imported, param),
2731
+ param->getSourceRange ().getBegin ());
2732
+ return nullptr ;
2733
+ }
2734
+ parameters.push_back (*paramInfo);
2728
2735
++index;
2729
2736
}
2730
2737
@@ -3349,8 +3356,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
3349
3356
++nameIndex;
3350
3357
3351
3358
// Set up the parameter info
3352
- auto paramInfo = getParameterInfo (this , param, name, swiftParamTy, isInOut,
3353
- isParamTypeImplicitlyUnwrapped);
3359
+ auto paramInfo = * getParameterInfo (this , param, name, swiftParamTy, isInOut,
3360
+ isParamTypeImplicitlyUnwrapped);
3354
3361
3355
3362
// Determine whether we have a default argument.
3356
3363
if (kind == SpecialMethodKind::Regular ||
0 commit comments