Split Expression::CallbackReference and Expresison::FunctionReference

This commit is contained in:
Olivier Goffart 2022-12-01 15:27:31 +01:00 committed by Olivier Goffart
parent 4672e54f5e
commit dfdbc942f6
14 changed files with 74 additions and 49 deletions

View file

@ -334,9 +334,9 @@ fn process_property(
fn recurse_expression(expr: &Expression, vis: &mut impl FnMut(&PropertyPath)) {
expr.visit(|sub| recurse_expression(sub, vis));
match expr {
Expression::PropertyReference(r) | Expression::CallbackReference(r) => {
vis(&r.clone().into())
}
Expression::PropertyReference(r)
| Expression::CallbackReference(r)
| Expression::FunctionReference(r) => vis(&r.clone().into()),
Expression::LayoutCacheAccess { layout_cache_prop, .. } => {
vis(&layout_cache_prop.clone().into())
}

View file

@ -119,6 +119,7 @@ fn simplify_expression(expr: &mut Expression) -> bool {
Expression::CallbackReference { .. } => false,
Expression::ElementReference { .. } => false,
// FIXME
Expression::FunctionReference { .. } => false,
Expression::LayoutCacheAccess { .. } => false,
Expression::SolveLayout { .. } => false,
Expression::ComputeLayoutInfo { .. } => false,

View file

@ -215,7 +215,9 @@ fn expression_for_property(element: &ElementRc, name: &str) -> ExpressionForProp
// Check that the expresison is valid in the new scope
let mut has_invalid = false;
e.expression.visit_recursive(&mut |ex| match ex {
Expression::CallbackReference(nr) | Expression::PropertyReference(nr) => {
Expression::CallbackReference(nr)
| Expression::PropertyReference(nr)
| Expression::FunctionReference(nr) => {
let e = nr.element();
if !Rc::ptr_eq(&e, &element)
&& Weak::ptr_eq(

View file

@ -570,11 +570,15 @@ impl Expression {
expression: r @ Expression::CallbackReference(..), ..
} => {
if let Some(x) = it.next() {
if matches!(r.ty(), Type::Function { .. }) {
ctx.diag.push_error("Cannot access fields of a function".into(), &x)
} else {
ctx.diag.push_error("Cannot access fields of callback".into(), &x)
}
ctx.diag.push_error("Cannot access fields of callback".into(), &x)
}
r
}
LookupResult::Expression {
expression: r @ Expression::FunctionReference(..), ..
} => {
if let Some(x) = it.next() {
ctx.diag.push_error("Cannot access fields of a function".into(), &x)
}
r
}
@ -1073,7 +1077,7 @@ fn continue_lookup_within_element(
member: Box::new(member),
}
} else {
Expression::CallbackReference(NamedReference::new(elem, &lookup_result.resolved_name))
Expression::FunctionReference(NamedReference::new(elem, &lookup_result.resolved_name))
}
} else {
let mut err = |extra: &str| {
@ -1293,6 +1297,10 @@ pub fn resolve_two_way_binding(
Some(n)
}
}
Expression::FunctionReference(..) => {
ctx.diag.push_error("Cannot bind to a function".into(), &node);
None
}
_ => {
ctx.diag.push_error(
"The expression in a two way binding must be a property reference".into(),