Skip to content

Commit

Permalink
Proper .60 compilation error when changing a property linked with a t…
Browse files Browse the repository at this point in the history
…wo way binding in a state

Instead of generating wrong code or panic
  • Loading branch information
ogoffart committed Jul 27, 2021
1 parent f544e67 commit e0fad7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sixtyfps_compiler/object_tree.rs
Expand Up @@ -839,7 +839,7 @@ impl Element {
.StatePropertyChange()
.filter_map(|s| {
lookup_property_from_qualified_name(s.QualifiedName(), &r, diag).map(
|(ne, _)| (ne, Expression::Uncompiled(s.BindingExpression().into())),
|(ne, _)| (ne, Expression::Uncompiled(s.BindingExpression().into()), s),
)
})
.collect(),
Expand Down Expand Up @@ -1361,7 +1361,7 @@ pub fn visit_element_expressions(
if let Some(cond) = s.condition.as_mut() {
vis(cond, None, &|| Type::Bool)
}
for (ne, e) in &mut s.property_changes {
for (ne, e, _) in &mut s.property_changes {
vis(e, Some(ne.name()), &|| {
ne.element().borrow().lookup_property(ne.name()).property_type
});
Expand Down Expand Up @@ -1408,7 +1408,7 @@ pub fn visit_all_named_references_in_element(
visit_element_expressions(elem, |expr, _, _| recurse_expression(expr, &mut vis));
let mut states = std::mem::take(&mut elem.borrow_mut().states);
for s in &mut states {
for (r, _) in &mut s.property_changes {
for (r, _, _) in &mut s.property_changes {
vis(r);
}
}
Expand Down Expand Up @@ -1482,7 +1482,7 @@ pub fn visit_all_expressions(
pub struct State {
pub id: String,
pub condition: Option<Expression>,
pub property_changes: Vec<(NamedReference, Expression)>,
pub property_changes: Vec<(NamedReference, Expression, syntax_nodes::StatePropertyChange)>,
}

#[derive(Debug, Clone)]
Expand Down
9 changes: 8 additions & 1 deletion sixtyfps_compiler/passes/lower_states.rs
Expand Up @@ -62,10 +62,17 @@ fn lower_state_in_element(
false_expr: Box::new(std::mem::take(&mut state_value)),
};
}
for (ne, expr) in state.property_changes {
for (ne, expr, node) in state.property_changes {
affected_properties.insert(ne.clone());
let e = ne.element();
let property_expr = expression_for_property(&e, ne.name());
if matches!(property_expr, Expression::TwoWayBinding(..)) {
diag.push_error(
format!("Cannot change the property '{}' in a state because it is initialized with a two-way binding", ne.name()),
&node
);
continue;
}
let new_expr = Expression::Condition {
condition: Box::new(Expression::BinaryExpression {
lhs: Box::new(state_property_ref.clone()),
Expand Down

0 comments on commit e0fad7f

Please sign in to comment.