Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
improve multiple matches error message; don't stop on first resolve e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
hlorenzi committed May 1, 2021
1 parent e4ca019 commit a540aac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "customasm"
version = "0.11.7"
version = "0.11.8"
edition = "2018"
authors = ["hlorenzi <https://hlorenzi.com>"]
description = "An assembler for custom, user-defined instruction sets!"
Expand Down
25 changes: 21 additions & 4 deletions src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl State

for invoc in &bankdata.invocations
{
let resolved = match invoc.kind
let maybe_resolved = match invoc.kind
{
asm::InvocationKind::Rule(_) =>
{
Expand All @@ -448,7 +448,7 @@ impl State
&invoc,
fileserver,
true,
&mut expr::EvalContext::new())?
&mut expr::EvalContext::new())
}

asm::InvocationKind::Data(_) =>
Expand All @@ -461,7 +461,7 @@ impl State
report.clone(),
&invoc,
fileserver,
true)?
true)
}

asm::InvocationKind::Label(_) =>
Expand All @@ -485,6 +485,12 @@ impl State
}
};

let resolved = match maybe_resolved
{
Ok(r) => r,
Err(_) => continue,
};

let expr_name = match invoc.kind
{
asm::InvocationKind::Rule(_) => "instruction",
Expand Down Expand Up @@ -705,9 +711,20 @@ impl State
{
if successful_candidates.len() > 1
{
report.error_span(
let _guard = report.push_parent(
"multiple matches for instruction",
&invocation.span);

for c in successful_candidates
{
let rule_group = &self.rulesets[c.0.rule_ref.ruleset_ref.index];
let rule = &rule_group.rules[c.0.rule_ref.index];

report.note_span(
"matching rule candidate:",
&rule.span);
}

return Err(())
}

Expand Down
2 changes: 1 addition & 1 deletion tests/rule_multiple.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
halt => 0x66
}

halt ; error: multiple matches
halt ; error: failed / error: multiple matches


; ::: include
Expand Down

0 comments on commit a540aac

Please sign in to comment.