Merge 'Return null when parameter is unbound' from Levy A.

Fix #1323.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1324
This commit is contained in:
Jussi Saurio
2025-04-13 17:02:03 +03:00
3 changed files with 6 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,11 @@ 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) {