From a9fee27bbb55293e2bb6853ad2e3c9954bf492e5 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 9 Sep 2026 01:39:54 +0000 Subject: [PATCH] Add test for symbolic arguments to templates. (#7736) Test passing a template argument or a symbolic argument to a template. Fix a bug in the template case where we'd crash when instantiating a dependent discarded expression, because conversion produced an `InstId::None` which the actions machinery did not expect and crashed on. --- toolchain/check/convert.cpp | 2 +- .../testdata/generic/template/argument.carbon | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/toolchain/check/convert.cpp b/toolchain/check/convert.cpp index 16ec2fba4a42..4f7f96973792 100644 --- a/toolchain/check/convert.cpp +++ b/toolchain/check/convert.cpp @@ -1886,7 +1886,7 @@ auto CategoryConverter::DoStep(const SemIR::InstId expr_id, if (target_.kind == ConversionTarget::Discarded) { DiscardInitializer(context_, expr_id); - return Done{SemIR::InstId::None}; + return Done{expr_id}; } else if (IsValidExprCategoryForConversionTarget(category, target_.kind)) { return Done{expr_id}; diff --git a/toolchain/check/testdata/generic/template/argument.carbon b/toolchain/check/testdata/generic/template/argument.carbon index f3eb9334d353..90806e22160f 100644 --- a/toolchain/check/testdata/generic/template/argument.carbon +++ b/toolchain/check/testdata/generic/template/argument.carbon @@ -25,6 +25,32 @@ fn G(x: X) { F(X, x); } +// --- forward_template_type_to_template.carbon +library "[[@TEST_NAME]]"; + +fn F(template T: type, unused x: T) {} + +fn ForwardTemplate(template T: type, x: T) { + F(T, x); +} + +fn CallForwardTemplate() { + ForwardTemplate({}, {}); +} + +// --- forward_generic_type_to_template.carbon +library "[[@TEST_NAME]]"; + +fn F(template T: type, unused x: T) {} + +fn ForwardGeneric(generic T: type, x: T) { + F(T, x); +} + +fn CallForwardGeneric() { + ForwardGeneric({}, {}); +} + // --- constant_nontype_argument.carbon library "[[@TEST_NAME]]";