Skip to content

Commit

Permalink
Fix declaring callback alias that override a property
Browse files Browse the repository at this point in the history
Do the check for existing property before handling of callback aliases

Fixes #5205
  • Loading branch information
ogoffart committed May 10, 2024
1 parent a6c3d2a commit 25ef8f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
32 changes: 16 additions & 16 deletions internal/compiler/object_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,22 +1049,6 @@ impl Element {
sig_decl.child_token(SyntaxKind::Identifier).map_or(false, |t| t.text() == "pure"),
);

if let Some(csn) = sig_decl.TwoWayBinding() {
r.bindings
.insert(name.clone(), BindingExpression::new_uncompiled(csn.into()).into());
r.property_declarations.insert(
name,
PropertyDeclaration {
property_type: Type::InferredCallback,
node: Some(sig_decl.into()),
visibility: PropertyVisibility::InOut,
pure,
..Default::default()
},
);
continue;
}

let PropertyLookupResult {
resolved_name: existing_name,
property_type: maybe_existing_prop_type,
Expand Down Expand Up @@ -1095,6 +1079,22 @@ impl Element {
continue;
}

if let Some(csn) = sig_decl.TwoWayBinding() {
r.bindings
.insert(name.clone(), BindingExpression::new_uncompiled(csn.into()).into());
r.property_declarations.insert(
name,
PropertyDeclaration {
property_type: Type::InferredCallback,
node: Some(sig_decl.into()),
visibility: PropertyVisibility::InOut,
pure,
..Default::default()
},
);
continue;
}

let args = sig_decl.Type().map(|node_ty| type_from_node(node_ty, diag, tr)).collect();
let return_type = sig_decl
.ReturnType()
Expand Down
3 changes: 3 additions & 0 deletions internal/compiler/tests/syntax/basic/signal.slint
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ export SubElements := Rectangle {

callback init;
// ^error{Cannot override callback 'init'}

callback width;
// ^error{Cannot declare callback 'width' when a property with the same name exists}
}
3 changes: 3 additions & 0 deletions internal/compiler/tests/syntax/lookup/callback_alias3.slint
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ export Xxx := Rectangle {
return "hello";
// ^error{Cannot convert string to int}
}

callback x <=> compute_alias;
// ^error{Cannot declare callback 'x' when a property with the same name exists}
}
}

0 comments on commit 25ef8f8

Please sign in to comment.