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.
This commit is contained in:
Richard Smith
2026-09-09 01:39:54 +00:00
committed by GitHub
parent d92a981083
commit a9fee27bbb
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -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};
@@ -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]]";