mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user