From 92e635c2f0ad39c80fe079f58073daa1ebfaa14a Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 27 Feb 2025 12:06:02 -0500 Subject: [PATCH] Use the constant value unconditionally in deduce diagnostic (#5034) When finding the binding entity name, always go through the binding instruction's constant value to get a canonical instruction which will always have an entity name attached to it. Currently the only instructions in this position without an entity name are ImportRefLoaded. But other indirect instructions may exist in the future, which evaluate to an AnyBindName but are not themselves one. So this makes the code more robust to change in the future. --- toolchain/check/deduce.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/toolchain/check/deduce.cpp b/toolchain/check/deduce.cpp index 8036a7b71138..5040f544c2bc 100644 --- a/toolchain/check/deduce.cpp +++ b/toolchain/check/deduce.cpp @@ -511,11 +511,10 @@ auto DeductionContext::Deduce() -> bool { static auto GetEntityNameForGenericBinding(Context& context, SemIR::InstId binding_id) -> SemIR::NameId { - // If `binding_id` is imported, it may not have an entity name. Get a - // canonical local instruction from its constant value which does. - if (context.insts().Is(binding_id)) { - binding_id = context.constant_values().GetConstantInstId(binding_id); - } + // If `binding_id` is imported (or referenced indirectly perhaps in the + // future), it may not have an entity name. Get a canonical local instruction + // from its constant value which does. + binding_id = context.constant_values().GetConstantInstId(binding_id); if (auto bind_name = context.insts().TryGetAs(binding_id)) {