Skip to content

Commit b1dff4a

Browse files
committed
C++Interop: Don't create default argument expressions that are templated
SwiftDeclSynthesizer::makeDefaultArgument does not create substituion map while creating the implicit FuncDecl which leads to TypeChecker complaining about the absence when there are type parameters. Avoid importing such C++ functions for now.
1 parent 11954f4 commit b1dff4a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,12 +2616,11 @@ bool ClangImporter::Implementation::isDefaultArgSafeToImport(
26162616
return true;
26172617
}
26182618

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) {
26252624
// Figure out the name for this parameter.
26262625
Identifier bodyName = impl->importFullName(param, impl->CurrentVersion)
26272626
.getBaseIdentifier(impl->SwiftContext);
@@ -2657,9 +2656,11 @@ static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl,
26572656
// Swift doesn't support default values of inout parameters.
26582657
// TODO: support default arguments of constructors
26592658
// (https://github.com/apple/swift/issues/70124)
2659+
// TODO: support params with template parameters
26602660
if (param->hasDefaultArg() && !isInOut &&
26612661
!isa<clang::CXXConstructorDecl>(param->getDeclContext()) &&
2662-
impl->isDefaultArgSafeToImport(param)) {
2662+
impl->isDefaultArgSafeToImport(param) &&
2663+
!isa<clang::FunctionTemplateDecl>(param->getDeclContext())) {
26632664
SwiftDeclSynthesizer synthesizer(*impl);
26642665
if (CallExpr *defaultArgExpr = synthesizer.makeDefaultArgument(
26652666
param, swiftParamTy, paramInfo->getParameterNameLoc())) {
@@ -2724,7 +2725,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
27242725

27252726
auto paramInfo = getParameterInfo(this, param, name, swiftParamTy, isInOut,
27262727
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);
27282735
++index;
27292736
}
27302737

@@ -3349,8 +3356,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
33493356
++nameIndex;
33503357

33513358
// 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);
33543361

33553362
// Determine whether we have a default argument.
33563363
if (kind == SpecialMethodKind::Regular ||

0 commit comments

Comments
 (0)