Disallow duplicated callback declarations

A duplicated callback would silently overwrite the previous declaration,
which is counter-intuitive.
This commit is contained in:
Simon Hausmann 2022-11-15 16:58:33 +01:00 committed by Simon Hausmann
parent bae5dbfa16
commit 27db2bdcc6
3 changed files with 20 additions and 10 deletions

View file

@ -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() {

View file

@ -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}
}

View file

@ -3,6 +3,8 @@
SubElements := Rectangle {
callback foobar;
callback foobar;
// ^error{Duplicated callback declaration}
callback callback_with_arg(int, string);