From 3d128a48a32cab4e07c520449eefca5a4f58077a Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Mon, 24 Apr 2023 07:38:37 +0000 Subject: [PATCH] Improve error message on unknown jump labels --- pio-parser/src/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pio-parser/src/lib.rs b/pio-parser/src/lib.rs index e1c2882..5237a24 100644 --- a/pio-parser/src/lib.rs +++ b/pio-parser/src/lib.rs @@ -213,10 +213,11 @@ impl<'a> ProgramState<'a> { } fn resolve(&self, name: &str) -> i32 { - match self.defines.get(name) { - Some(v) => v.1, - None => self.file_state.defines[name].1, - } + self.defines + .get(name) + .or_else(|| self.file_state.defines.get(name)) + .unwrap_or_else(|| panic!("Unknown label {}", name)) + .1 } fn public_defines(&self) -> HashMap { @@ -439,3 +440,14 @@ fn test_side_set() { assert_eq!(p.origin, Some(5)); assert_eq!(p.wrap, (1, 1)); } + +#[test] +#[should_panic(expected = "Unknown label some_unknown_label")] +fn test_unknown_label() { + let _ = Parser::<32>::parse_program( + " + jmp some_unknown_label + ", + ) + .unwrap(); +}