diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-10-31 17:27:55 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-10-31 17:29:30 +1300 |
commit | 617c7df875171cd7b14983b14f4368120f265cce (patch) | |
tree | 10460a874243e2fdba20233c875171775742ef63 /src/symbol_resolver.rs | |
parent | 65d409e389d437d506a841ff5eb0a2a5d977a7d5 (diff) | |
download | bedrock-asm-617c7df875171cd7b14983b14f4368120f265cce.zip |
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.
Diffstat (limited to 'src/symbol_resolver.rs')
-rw-r--r-- | src/symbol_resolver.rs | 8 |
1 files changed, 4 insertions, 4 deletions
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<TrackedSymbol>, /// All unresolved references. pub unresolved: Vec<TrackedSymbol>, - /// 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<HeirarchicalSourceUnit>, pub root_unit_ids: Vec<usize>, @@ -122,10 +122,10 @@ impl SymbolResolver { fn add_definitions(&mut self, definitions: Vec<Symbol>, 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; |