Skip to content

Commit

Permalink
Prevent assignments on relative references
Browse files Browse the repository at this point in the history
It is a really weird thing to do, but on a twisted way I can see how
someone could think of such a monstrosity. Panicking on such a case is
not valid because that's not the fault from the assembler but from the
programmer, and so a proper message should be displayed instead.

This was detected via the fuzzer, but it was a side effect from
e7c5e63 ("Evaluate bare numbers as decimal values").

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Jan 9, 2025
1 parent e2c322a commit ec0831e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/xixanta/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ impl<'a> Assembler<'a> {
Ok(right)
}

// Evaluate the given node as a relative reference.
fn evaluate_anonymous_relative_reference(&mut self, node: &PNode) -> Result<Bundle, Error> {
self.literal_mode = Some(LiteralMode::Plain);

Expand Down Expand Up @@ -957,7 +958,12 @@ impl<'a> Assembler<'a> {
}),
}
}
_ => panic!("unexpected evaluation of relative reference"),
Stage::Context => Err(Error {
line: node.value.line,
source: self.source_for(node),
global: false,
message: "trying to evaluate a relative reference as a bare value".to_string(),
}),
}
}

Expand Down Expand Up @@ -2263,6 +2269,16 @@ mod tests {
);
}

#[test]
fn trying_to_assign_on_relative_reference() {
assert_error(
"Var = :-",
1,
false,
"trying to evaluate a relative reference as a bare value",
);
}

#[test]
fn unknown_variables() {
assert_error(
Expand Down

0 comments on commit ec0831e

Please sign in to comment.