mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:21:16 +01:00
When diagnosing name used before declared, set the location of the usage (#4860)
Done by adding a poisoning location for each poisoned name. Part of #4622.
This commit is contained in:
@@ -175,7 +175,7 @@ auto DeclNameStack::AddNameOrDiagnose(NameContext name_context,
|
||||
SemIR::InstId target_id,
|
||||
SemIR::AccessKind access_kind) -> void {
|
||||
if (name_context.state == DeclNameStack::NameContext::State::Poisoned) {
|
||||
context_->DiagnosePoisonedName(target_id);
|
||||
context_->DiagnosePoisonedName(name_context.poisoning_loc_id, target_id);
|
||||
} else if (auto id = name_context.prev_inst_id(); id.has_value()) {
|
||||
context_->DiagnoseDuplicateName(target_id, id);
|
||||
} else {
|
||||
@@ -188,7 +188,8 @@ auto DeclNameStack::LookupOrAddName(NameContext name_context,
|
||||
SemIR::AccessKind access_kind)
|
||||
-> SemIR::ScopeLookupResult {
|
||||
if (name_context.state == NameContext::State::Poisoned) {
|
||||
return SemIR::ScopeLookupResult::MakePoisoned();
|
||||
return SemIR::ScopeLookupResult::MakePoisoned(
|
||||
name_context.poisoning_loc_id);
|
||||
}
|
||||
if (auto id = name_context.prev_inst_id(); id.has_value()) {
|
||||
return SemIR::ScopeLookupResult::MakeFound(id, access_kind);
|
||||
@@ -267,6 +268,7 @@ auto DeclNameStack::ApplyAndLookupName(NameContext& name_context,
|
||||
name_context.initial_scope_index);
|
||||
if (lookup_result.is_poisoned()) {
|
||||
name_context.unresolved_name_id = name_id;
|
||||
name_context.poisoning_loc_id = lookup_result.poisoning_loc_id();
|
||||
name_context.state = NameContext::State::Poisoned;
|
||||
} else if (!lookup_result.is_found()) {
|
||||
// Invalid indicates an unresolved name. Store it and return.
|
||||
|
||||
Reference in New Issue
Block a user