Avoid witnesses in redecls when handling errors in handle_impl (#5409)

When we fill the witness table with errors, set the witness id to an
error too, which signals to impl lookups to not use the impl.

Make the use of the `Impl` from the store more consistent once it's been
added to the store (or known to be there already).
This commit is contained in:
Dana Jansens
2025-05-02 19:49:06 +00:00
committed by GitHub
parent 1f268b5d8b
commit 90898a8e19
8 changed files with 96 additions and 173 deletions
+12 -11
View File
@@ -243,19 +243,20 @@ auto FinishImplWitness(Context& context, SemIR::ImplId impl_id) -> void {
}
auto FillImplWitnessWithErrors(Context& context, SemIR::Impl& impl) -> void {
if (impl.witness_id.has_value() &&
impl.witness_id != SemIR::ErrorInst::InstId) {
auto witness = context.insts().GetAs<SemIR::ImplWitness>(impl.witness_id);
auto witness_table = context.insts().GetAs<SemIR::ImplWitnessTable>(
witness.witness_table_id);
auto witness_block =
context.inst_blocks().GetMutable(witness_table.elements_id);
for (auto& elem : witness_block) {
if (elem == SemIR::ImplWitnessTablePlaceholder::TypeInstId) {
elem = SemIR::ErrorInst::InstId;
}
if (impl.witness_id == SemIR::ErrorInst::InstId) {
return;
}
auto witness = context.insts().GetAs<SemIR::ImplWitness>(impl.witness_id);
auto witness_table =
context.insts().GetAs<SemIR::ImplWitnessTable>(witness.witness_table_id);
auto witness_block =
context.inst_blocks().GetMutable(witness_table.elements_id);
for (auto& elem : witness_block) {
if (elem == SemIR::ImplWitnessTablePlaceholder::TypeInstId) {
elem = SemIR::ErrorInst::InstId;
}
}
impl.witness_id = SemIR::ErrorInst::InstId;
}
auto AssignImplIdInWitness(Context& context, SemIR::ImplId impl_id,