From 617c7df875171cd7b14983b14f4368120f265cce Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 31 Oct 2024 17:27:55 +1300 Subject: Fix reported source location in symbol redefinition errors The reported location of the original definition of a redefined symbol was incorrect. The index stored alongside a redefined symbol was the ID of the source unit which owns the original definition, but in the error printing code it was being treated as the index of the original definition of that symbol in the definitions list of the resolver. This was causing the reported location of the original definition to be that of an unrelated symbol. To fix this issue, the index stored alongside a redefined symbol is now the index of the original definition of that symbol in the definitions list of the resolver. --- src/symbol_resolver.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/symbol_resolver.rs') diff --git a/src/symbol_resolver.rs b/src/symbol_resolver.rs index 38163e3..c96ba67 100644 --- a/src/symbol_resolver.rs +++ b/src/symbol_resolver.rs @@ -10,7 +10,7 @@ pub struct SymbolResolver { pub resolved: Vec, /// All unresolved references. pub unresolved: Vec, - /// Contains the ID of the owner of the original definition. + /// Contains the `definitions` index of the original definition. pub redefinitions: Vec<(TrackedSymbol, usize)>, pub source_units: Vec, pub root_unit_ids: Vec, @@ -122,10 +122,10 @@ impl SymbolResolver { fn add_definitions(&mut self, definitions: Vec, source_id: usize, source_role: SourceRole) { for symbol in definitions { - let predicate = |d: &&TrackedSymbol| { &d.symbol.name == &symbol.name }; - if let Some(def) = self.definitions.iter().find(predicate) { + let predicate = |d: &TrackedSymbol| { &d.symbol.name == &symbol.name }; + if let Some(original) = self.definitions.iter().position(predicate) { let definition = TrackedSymbol { symbol, source_id, source_role }; - let redefinition = (definition, def.source_id); + let redefinition = (definition, original); self.redefinitions.push(redefinition); } else { let predicate = |s: &mut TrackedSymbol| s.symbol.name == symbol.name; -- cgit v1.2.3-70-g09d2