Ensure a location for monomorphization diagnostics in call argument deduction (#7401)

If the deduction fails while forming the parameter type, ensure that we
print an actual diagnostic saying what went wrong.

And always ensure that an invalid array bounds error points at a
location. The `inst_id` given to `EvalConstantInst` always has a
location, but the `bounds_id` instruction inside it may be canonical
when it's coming from inside a larger type. So when it is, fall back to
using the location of the whole array inst.
This commit is contained in:
Dana Jansens
2026-06-25 22:37:14 +00:00
committed by GitHub
parent bd8c565c74
commit 5aae6a1ca5
4 changed files with 87 additions and 13 deletions
+19 -7
View File
@@ -543,13 +543,6 @@ auto DeductionContext::CheckDeductionIsComplete() -> bool {
// that incorrectly.
auto binding_type_id = context().insts().Get(binding_id).type_id();
if (binding_type_id.is_symbolic()) {
auto param_type_const_id =
SubstConstant(context(), SemIR::LocId(binding_id),
binding_type_id.AsConstantId(), substitutions_);
CARBON_CHECK(param_type_const_id.has_value());
binding_type_id =
context().types().GetTypeIdForTypeConstantId(param_type_const_id);
Diagnostics::AnnotationScope annotate_diagnostics(
&context().emitter(), [&](auto& builder) {
if (diagnose_) {
@@ -557,6 +550,25 @@ auto DeductionContext::CheckDeductionIsComplete() -> bool {
builder);
}
});
{
Diagnostics::ContextScope diag_context(
&context().emitter(), [&](auto& builder) {
CARBON_DIAGNOSTIC(
SubstitutingGenericParamType, Context,
"constructed invalid specific for {0} from argument",
SemIR::TypeId);
builder.Context(loc_id_, SubstitutingGenericParamType,
binding_type_id);
});
auto param_type_const_id =
SubstConstant(context(), SemIR::LocId(binding_id),
binding_type_id.AsConstantId(), substitutions_);
CARBON_CHECK(param_type_const_id.has_value());
binding_type_id =
context().types().GetTypeIdForTypeConstantId(param_type_const_id);
}
auto converted_arg_id =
diagnose_ ? ConvertToValueOfType(context(), loc_id_, deduced_arg_id,
binding_type_id)