@@ -2616,12 +2616,10 @@ 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 *> getParameterInfo (
2620
+ ClangImporter::Implementation *impl, const clang::ParmVarDecl *param,
2621
+ const Identifier &name, const swift::Type &swiftParamTy, const bool isInOut,
2622
+ const bool isParamTypeImplicitlyUnwrapped, const bool isTemplated) {
2625
2623
// Figure out the name for this parameter.
2626
2624
Identifier bodyName = impl->importFullName (param, impl->CurrentVersion )
2627
2625
.getBaseIdentifier (impl->SwiftContext );
@@ -2660,6 +2658,13 @@ static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl,
2660
2658
if (param->hasDefaultArg () && !isInOut &&
2661
2659
!isa<clang::CXXConstructorDecl>(param->getDeclContext ()) &&
2662
2660
impl->isDefaultArgSafeToImport (param)) {
2661
+
2662
+ // If this was a default argument expression with template parameter, return
2663
+ // std::nullopt
2664
+ if (isTemplated) {
2665
+ return std::nullopt;
2666
+ }
2667
+
2663
2668
SwiftDeclSynthesizer synthesizer (*impl);
2664
2669
if (CallExpr *defaultArgExpr = synthesizer.makeDefaultArgument (
2665
2670
param, swiftParamTy, paramInfo->getParameterNameLoc ())) {
@@ -2723,8 +2728,15 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
2723
2728
name = argNames[index];
2724
2729
2725
2730
auto paramInfo = getParameterInfo (this , param, name, swiftParamTy, isInOut,
2726
- isParamTypeImplicitlyUnwrapped);
2727
- parameters.push_back (paramInfo);
2731
+ isParamTypeImplicitlyUnwrapped,
2732
+ swiftParamTy->hasTypeParameter ());
2733
+ if (!paramInfo.has_value ()) {
2734
+ addImportDiagnostic (param,
2735
+ Diagnostic (diag::parameter_type_not_imported, param),
2736
+ param->getSourceRange ().getBegin ());
2737
+ return nullptr ;
2738
+ }
2739
+ parameters.push_back (*paramInfo);
2728
2740
++index;
2729
2741
}
2730
2742
@@ -3349,8 +3361,9 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
3349
3361
++nameIndex;
3350
3362
3351
3363
// Set up the parameter info
3352
- auto paramInfo = getParameterInfo (this , param, name, swiftParamTy, isInOut,
3353
- isParamTypeImplicitlyUnwrapped);
3364
+ auto paramInfo = *getParameterInfo (this , param, name, swiftParamTy, isInOut,
3365
+ isParamTypeImplicitlyUnwrapped,
3366
+ /* isTemplated*/ false );
3354
3367
3355
3368
// Determine whether we have a default argument.
3356
3369
if (kind == SpecialMethodKind::Regular ||
0 commit comments