fix: return null when parameter is unbound

This commit is contained in:
Levy A. 2025-04-12 17:40:29 -03:00
parent df11562f69
commit 5c0b112125
3 changed files with 3 additions and 12 deletions

View file

@ -1,5 +1,3 @@
use std::num::NonZero;
use thiserror::Error;
#[derive(Debug, Error, miette::Diagnostic)]
@ -49,8 +47,6 @@ pub enum LimboError {
Constraint(String),
#[error("Extension error: {0}")]
ExtensionError(String),
#[error("Unbound parameter at index {0}")]
Unbound(NonZero<usize>),
#[error("Runtime error: integer overflow")]
IntegerOverflow,
#[error("Schema is locked for write")]

View file

@ -4395,12 +4395,7 @@ pub fn op_variable(
let Insn::Variable { index, dest } = insn else {
unreachable!("unexpected Insn {:?}", insn)
};
state.registers[*dest] = Register::OwnedValue(
state
.get_parameter(*index)
.ok_or(LimboError::Unbound(*index))?
.clone(),
);
state.registers[*dest] = Register::OwnedValue(state.get_parameter(*index));
state.pc += 1;
Ok(InsnFunctionStepResult::Step)
}

View file

@ -284,8 +284,8 @@ impl ProgramState {
self.parameters.insert(index, value);
}
pub fn get_parameter(&self, index: NonZero<usize>) -> Option<&OwnedValue> {
self.parameters.get(&index)
pub fn get_parameter(&self, index: NonZero<usize>) -> OwnedValue {
self.parameters.get(&index).cloned().unwrap_or(OwnedValue::Null)
}
pub fn reset(&mut self) {