Avoid ToTokenOnly for the AddrSelfIsNonRef diagnostic (#5371)

The location of the diagnostic is an instruction id, not a parse node.
Converting to a parse node to call ToTokenOnly will drop the descendents
of the instruction being diagnosed, but the diagnostic is about the
whole instruction not just the root parse node of whatever instruction
it happens to be.
This commit is contained in:
Dana Jansens
2025-04-29 15:25:27 +00:00
committed by GitHub
parent 7c85397f8b
commit e2984d9fc3
2 changed files with 5 additions and 7 deletions
+1 -3
View File
@@ -261,9 +261,7 @@ auto MatchContext::DoEmitPatternMatch(Context& context,
default:
CARBON_DIAGNOSTIC(AddrSelfIsNonRef, Error,
"`addr self` method cannot be invoked on a value");
context.emitter().Emit(
context.insts().GetCanonicalLocId(entry.scrutinee_id).ToTokenOnly(),
AddrSelfIsNonRef);
context.emitter().Emit(entry.scrutinee_id, AddrSelfIsNonRef);
// Add fake reference expression to preserve invariants.
auto scrutinee = context.insts().GetWithLocId(entry.scrutinee_id);
scrutinee_ref_id = AddInstWithCleanup<SemIR::TemporaryStorage>(