Fix declaring callback alias that override a property

Do the check for existing property before handling of callback aliases

Fixes #5205
This commit is contained in:
Olivier Goffart 2024-05-10 11:37:38 +02:00
parent a6c3d2a63f
commit 25ef8f8711
3 changed files with 22 additions and 16 deletions

View file

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

View file

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

View file

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