mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
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:
parent
008837ccdc
commit
2f33a4b407
1 changed files with 14 additions and 5 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue