Skip to content

Commit

Permalink
Don't panic when an unresolved alias has a binding
Browse files Browse the repository at this point in the history
Fixes #3085

When there are both a binding and a two way binding, we must keep the
two way binding in our bindings map. Otherwise type inference will not
work
  • Loading branch information
ogoffart committed Jul 14, 2023
1 parent c990660 commit 57e9b5b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
54 changes: 24 additions & 30 deletions internal/compiler/object_tree.rs
Expand Up @@ -924,17 +924,16 @@ impl Element {
);

if let Some(csn) = prop_decl.BindingExpression() {
if r.bindings
.insert(
prop_name.to_string(),
BindingExpression::new_uncompiled(csn.into()).into(),
)
.is_some()
{
diag.push_error(
"Duplicated property binding".into(),
&prop_decl.DeclaredIdentifier(),
);
match r.bindings.entry(prop_name.to_string()) {
Entry::Vacant(e) => {
e.insert(BindingExpression::new_uncompiled(csn.into()).into());
}
Entry::Occupied(_) => {
diag.push_error(
"Duplicated property binding".into(),
&prop_decl.DeclaredIdentifier(),
);
}
}
}
if let Some(csn) = prop_decl.TwoWayBinding() {
Expand Down Expand Up @@ -1140,17 +1139,14 @@ impl Element {
);
continue;
}
if r.bindings
.insert(
resolved_name.into_owned(),
BindingExpression::new_uncompiled(con_node.clone().into()).into(),
)
.is_some()
{
diag.push_error(
match r.bindings.entry(resolved_name.into_owned()) {
Entry::Vacant(e) => {
e.insert(BindingExpression::new_uncompiled(con_node.clone().into()).into());
}
Entry::Occupied(_) => diag.push_error(
"Duplicated callback".into(),
&con_node.child_token(SyntaxKind::Identifier).unwrap(),
);
),
}
}

Expand Down Expand Up @@ -1525,16 +1521,14 @@ impl Element {
);
}

if self
.bindings
.insert(
lookup_result.resolved_name.to_string(),
BindingExpression::new_uncompiled(b).into(),
)
.is_some()
{
diag.push_error("Duplicated property binding".into(), &name_token);
}
match self.bindings.entry(lookup_result.resolved_name.to_string()) {
Entry::Occupied(_) => {
diag.push_error("Duplicated property binding".into(), &name_token);
}
Entry::Vacant(entry) => {
entry.insert(BindingExpression::new_uncompiled(b).into());
}
};
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/compiler/tests/syntax/lookup/callback_alias2.slint
Expand Up @@ -10,4 +10,12 @@ export Xxx := Rectangle {
callback bar(int) -> int;
bar <=> foo.hello;
// ^error{Unknown property bar in Rectangle}


// #3085
callback row-pointer-event <=> dontexist;
// ^error{Unknown unqualified identifier 'dontexist'}
// ^^error{Binding to callback 'row-pointer-event' must bind to another callback}
row-pointer-event => {}
// ^error{Duplicated callback}
}
Expand Up @@ -23,4 +23,10 @@ export X := Rectangle {
property <string> alias_to_background <=> auto_background;
// ^error{The property does not have the same type as the bound property}


property abc <=> self.opacity;
abc: "eee";
// ^error{Duplicated property binding}


}

0 comments on commit 57e9b5b

Please sign in to comment.