From 68ce788d00fe0b8353b7e6aee5ce8dfae564ea5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Thu, 9 Jan 2025 22:49:32 +0100 Subject: [PATCH] Improve error message on unknown variable/scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 18 ++++++++---------- lib/xixanta/src/object.rs | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 1f7c9a5..f190d33 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -791,10 +791,7 @@ impl<'a> Assembler<'a> { Ok(v) } Err(err) => Err(Error { - message: format!( - "no prefix was given to operand and {} either", - err.message - ), + message: err.message, line: node.value.line, source: self.source_for(node), global: false, @@ -2239,15 +2236,16 @@ mod tests { #[test] fn bad_variable_but_valid_identifier_in_instruction() { assert_error( - "adc Variable", - 1, false, - "no prefix was given to operand and could not find variable 'Variable' in the global scope either", - ); + "adc Variable", + 1, + false, + "could not find variable 'Variable' in the global scope", + ); assert_error( "adc Scoped::Variable", 1, false, - "no prefix was given to operand and did not find scope 'Scoped' either", + "could not find scope 'Scoped'", ); } @@ -2292,7 +2290,7 @@ mod tests { "lda #Scope::Variable", 1, false, - "'e' is not a decimal value and did not find scope 'Scope' either", + "'e' is not a decimal value and could not find scope 'Scope' either", ); assert_error( r#" diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs index 77ab8a6..ad02747 100644 --- a/lib/xixanta/src/object.rs +++ b/lib/xixanta/src/object.rs @@ -232,7 +232,7 @@ impl Context { } } }, - None => Err(format!("did not find scope '{}'", scope_name)), + None => Err(format!("could not find scope '{}'", scope_name)), } }