interpreter: Fix panic when a model return invalid value

This fixes the test on tests/cases/model/models when using the rust
interpreter, as the second test has a "broken" model, the data is left
uninitialized, and this causes a data of the wrong type which causes
panic when it is being used.
This commit is contained in:
Olivier Goffart 2025-07-02 18:35:39 +02:00
parent 008837ccdc
commit 2f33a4b407

View file

@ -155,11 +155,20 @@ pub fn eval_expression(expression: &Expression, local_context: &mut EvalLocalCon
crate::dynamic_item_tree::SPECIAL_PROPERTY_INDEX,
)
.unwrap(),
Expression::RepeaterModelReference { element } => load_property_helper(&ComponentInstance::InstanceRef(local_context.component_instance),
&element.upgrade().unwrap().borrow().base_type.as_component().root_element,
crate::dynamic_item_tree::SPECIAL_PROPERTY_MODEL_DATA,
)
.unwrap(),
Expression::RepeaterModelReference { element } => {
let value = load_property_helper(&ComponentInstance::InstanceRef(local_context.component_instance),
&element.upgrade().unwrap().borrow().base_type.as_component().root_element,
crate::dynamic_item_tree::SPECIAL_PROPERTY_MODEL_DATA,
)
.unwrap();
if matches!(value, Value::Void) {
// Uninitialized model data (because the model returned None) should still be initialized to the default value of the type
default_value_for_type(&expression.ty())
} else {
value
}
},
Expression::FunctionParameterReference { index, .. } => {
local_context.function_arguments[*index].clone()
}