Disallow callback overrides as well

This commit is contained in:
Simon Hausmann 2022-11-15 18:11:49 +01:00 committed by Simon Hausmann
parent 27db2bdcc6
commit 9bb9ac3c39
2 changed files with 36 additions and 17 deletions

View file

@ -848,27 +848,38 @@ impl Element {
continue;
}
let PropertyLookupResult {
resolved_name: existing_name,
property_type: maybe_existing_prop_type,
..
} = r.lookup_property(&name);
if !matches!(maybe_existing_prop_type, Type::Invalid) {
if r.property_declarations.contains_key(&name) {
diag.push_error(
"Duplicated callback declaration".into(),
&sig_decl.DeclaredIdentifier(),
);
} else {
diag.push_error(
format!("Cannot override callback '{}'", existing_name),
&sig_decl.DeclaredIdentifier(),
)
}
}
let args = sig_decl.Type().map(|node_ty| type_from_node(node_ty, diag, tr)).collect();
let return_type = sig_decl
.ReturnType()
.map(|ret_ty| Box::new(type_from_node(ret_ty.Type(), diag, tr)));
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(),
);
}
r.property_declarations.insert(
name,
PropertyDeclaration {
property_type: Type::Callback { return_type, args },
node: Some(Either::Right(sig_decl)),
visibility: PropertyVisibility::InOut,
..Default::default()
},
);
}
for con_node in node.CallbackConnection() {