Fix panic when binding Path's commands property to a model entry's field

Fixes #2466
This commit is contained in:
Simon Hausmann 2023-04-03 14:51:24 +02:00 committed by Simon Hausmann
parent ef2120bd0a
commit d87af7e917
3 changed files with 21 additions and 7 deletions

View file

@ -1,6 +1,12 @@
# Changelog
All notable changes to this project are documented in this file.
## Unreleased
### General
- Fixed compiler panic when binding `Path`'s `commands` property to the field of a model entry.
## [1.0.0] - 2023-04-03
### General

View file

@ -37,12 +37,11 @@ pub fn compile_paths(
let element_types = &accepted_type.additional_accepted_child_types;
let mut elem = elem_.borrow_mut();
let commands_binding =
elem_.borrow_mut().bindings.remove("commands").map(RefCell::into_inner);
let path_data_binding = if let Some(commands_expr) =
elem.bindings.remove("commands").map(RefCell::into_inner)
{
if let Some(path_child) = elem.children.iter().find(|child| {
let path_data_binding = if let Some(commands_expr) = commands_binding {
if let Some(path_child) = elem_.borrow().children.iter().find(|child| {
element_types
.contains_key(&child.borrow().base_type.as_builtin().native_class.class_name)
}) {
@ -72,11 +71,15 @@ pub fn compile_paths(
)
.into(),
_ => {
diag.push_error("The commands property only accepts strings".into(), &*elem);
diag.push_error(
"The commands property only accepts strings".into(),
&*elem_.borrow(),
);
return;
}
}
} else {
let mut elem = elem_.borrow_mut();
let new_children = Vec::with_capacity(elem.children.len());
let old_children = std::mem::replace(&mut elem.children, new_children);
@ -111,7 +114,7 @@ pub fn compile_paths(
Expression::PathData(crate::expression_tree::Path::Elements(path_data)).into()
};
elem.bindings.insert("elements".into(), RefCell::new(path_data_binding));
elem_.borrow_mut().bindings.insert("elements".into(), RefCell::new(path_data_binding));
});
}

View file

@ -32,4 +32,9 @@ export TestCase := Rectangle {
}
Test2 {}
property <[{commands: string}]> model: [{commands: "M 0 0 L 0 100 A 1 1 0 0 0 100 100 L 100 0 Z"}];
for entry in model: Path {
commands: entry.commands; // Don't panic
}
}