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:
Richard Smith
2026-09-19 00:02:49 +00:00
committed by GitHub
parent d037848a96
commit 76e7fc5900
24 changed files with 223 additions and 167 deletions
+12 -3
View File
@@ -349,15 +349,24 @@ class Stringifier {
auto StringifyInst(InstId /*inst_id*/, ConstType inst) -> void {
*out_ << "const ";
// `const (const T)` is the same type as `const T`, so don't print a chain
// of `const`s.
// TODO: Do this generically for all type qualifiers, and don't repeat
// qualifiers in types like `const (partial (const T))`.
auto inner_id = inst.inner_id;
while (auto inner_const = sem_ir_->insts().TryGetAs<ConstType>(inner_id)) {
inner_id = inner_const->inner_id;
}
// Add parentheses if required.
if (GetPrecedence(sem_ir_->insts().Get(inst.inner_id).kind()) <
if (GetPrecedence(sem_ir_->insts().Get(inner_id).kind()) <
GetPrecedence(ConstType::Kind)) {
*out_ << "(";
// Note the `inst.inner_id` ends up here.
// Note the `inner_id` ends up here.
step_stack_->PushString(")");
}
step_stack_->PushInstId(inst.inner_id);
step_stack_->PushInstId(inner_id);
}
auto StringifyInst(InstId /*inst_id*/, CppTemplateNameType inst) -> void {