mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:24:46 +01:00
Preserve the type-as-written for bindings and use it in diagnostics. (#7804)
In the `EntityName` for a binding, preserve the `TypeInstId` describing how the type was written. When a diagnostic refers to that type via `TypeOfInstId`, use the type-as-written in the diagnostic rather than the canonical type. Assisted-by: Claude Opus via Antigravity
This commit is contained in:
@@ -92,8 +92,9 @@ auto MakeEmptyRegion(Context& context, SemIR::InstId result_id)
|
||||
}
|
||||
|
||||
auto AddBindingEntityName(Context& context, SemIR::NameId name_id,
|
||||
SemIR::InstId form_id, bool is_unused,
|
||||
BindingPhase phase) -> SemIR::EntityNameId {
|
||||
SemIR::TypeInstId type_inst_id, SemIR::InstId form_id,
|
||||
bool is_unused, BindingPhase phase)
|
||||
-> SemIR::EntityNameId {
|
||||
SemIR::EntityName entity_name = {
|
||||
.name_id = name_id,
|
||||
.parent_scope_id = context.scope_stack().PeekNameScopeId(),
|
||||
@@ -104,6 +105,7 @@ auto AddBindingEntityName(Context& context, SemIR::NameId name_id,
|
||||
entity_name.is_template = phase == BindingPhase::Template;
|
||||
}
|
||||
entity_name.form_id = form_id;
|
||||
entity_name.type_inst_id = type_inst_id;
|
||||
return context.entity_names().Add(entity_name);
|
||||
}
|
||||
|
||||
@@ -243,10 +245,14 @@ auto AddParamPattern(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
}();
|
||||
|
||||
auto entity_name_id = AddBindingEntityName(context, name_id,
|
||||
/*form_id=*/SemIR::InstId::None,
|
||||
/*is_unused=*/false,
|
||||
/*phase=*/BindingPhase::Runtime);
|
||||
// This pattern is synthesized rather than written in the source, so there is
|
||||
// no spelling to record for its type.
|
||||
auto entity_name_id =
|
||||
AddBindingEntityName(context, name_id,
|
||||
/*type_inst_id=*/SemIR::TypeInstId::None,
|
||||
/*form_id=*/SemIR::InstId::None,
|
||||
/*is_unused=*/false,
|
||||
/*phase=*/BindingPhase::Runtime);
|
||||
|
||||
auto pattern_type_id = GetPatternType(context, type_id);
|
||||
if (kind == ParamPatternKind::Var) {
|
||||
|
||||
Reference in New Issue
Block a user