Skip to content

Commit

Permalink
Merge pull request #43 from jannic/issue-30
Browse files Browse the repository at this point in the history
Improve error message on unknown jump labels
  • Loading branch information
ithinuel authored Apr 24, 2023
2 parents de11457 + 3d128a4 commit 35d9205
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pio-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, i32> {
Expand Down Expand Up @@ -451,3 +452,14 @@ fn test_side_set() {
}
);
}

#[test]
#[should_panic(expected = "Unknown label some_unknown_label")]
fn test_unknown_label() {
let _ = Parser::<32>::parse_program(
"
jmp some_unknown_label
",
)
.unwrap();
}

0 comments on commit 35d9205

Please sign in to comment.