Change DiagnoseDuplicateName to expect an inst ID for the duplicate. (#3616)

This makes duplicate and previous definition handling match. While we
may want to make both point more fine-grained at the name, the necessary
logic seems likely to be equivalent.

Note, I'm looking at this mainly due to duplicate names in imports,
where it's especially helpful to take an instruction instead of a parse
node. We'll eventually want to handle parse nodes from other imports
better, and I think this is the way it would most likely work.
This commit is contained in:
Jon Ross-Perkins
2024-01-18 23:23:31 +00:00
committed by GitHub
parent af14a2586a
commit d0fb4b5815
9 changed files with 21 additions and 25 deletions
+2 -3
View File
@@ -67,8 +67,7 @@ auto DeclNameStack::LookupOrAddName(NameContext name_context,
case NameContext::State::Unresolved:
if (!name_context.target_scope_id.is_valid()) {
context_->AddNameToLookup(name_context.parse_node,
name_context.unresolved_name_id, target_id);
context_->AddNameToLookup(name_context.unresolved_name_id, target_id);
} else {
auto& name_scope =
context_->name_scopes().Get(name_context.target_scope_id);
@@ -103,7 +102,7 @@ auto DeclNameStack::AddNameToLookup(NameContext name_context,
SemIR::InstId target_id) -> void {
auto existing_inst_id = LookupOrAddName(name_context, target_id);
if (existing_inst_id.is_valid()) {
context_->DiagnoseDuplicateName(name_context.parse_node, existing_inst_id);
context_->DiagnoseDuplicateName(target_id, existing_inst_id);
}
}