mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Disallow duplicated callback declarations
A duplicated callback would silently overwrite the previous declaration, which is counter-intuitive.
This commit is contained in:
parent
bae5dbfa16
commit
27db2bdcc6
3 changed files with 20 additions and 10 deletions
|
@ -852,15 +852,23 @@ impl Element {
|
|||
let return_type = sig_decl
|
||||
.ReturnType()
|
||||
.map(|ret_ty| Box::new(type_from_node(ret_ty.Type(), diag, tr)));
|
||||
r.property_declarations.insert(
|
||||
name,
|
||||
PropertyDeclaration {
|
||||
property_type: Type::Callback { return_type, args },
|
||||
node: Some(Either::Right(sig_decl)),
|
||||
visibility: PropertyVisibility::InOut,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
if r.property_declarations
|
||||
.insert(
|
||||
name,
|
||||
PropertyDeclaration {
|
||||
property_type: Type::Callback { return_type, args },
|
||||
node: Some(Either::Right(sig_decl.clone())),
|
||||
visibility: PropertyVisibility::InOut,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
diag.push_error(
|
||||
"Duplicated callback declaration".into(),
|
||||
&sig_decl.DeclaredIdentifier(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for con_node in node.CallbackConnection() {
|
||||
|
|
|
@ -15,7 +15,7 @@ Comp := Rectangle {
|
|||
|
||||
callback cb1(Rectangle);
|
||||
// ^error{'Rectangle' is not a valid type}
|
||||
callback cb1() -> Rectangle;
|
||||
callback cb2() -> Rectangle;
|
||||
// ^error{'Rectangle' is not a valid type}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
SubElements := Rectangle {
|
||||
callback foobar;
|
||||
callback foobar;
|
||||
// ^error{Duplicated callback declaration}
|
||||
|
||||
callback callback_with_arg(int, string);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue