Fixed property in when assign validation.

This commit is contained in:
Samuel Guerra 2023-04-13 22:43:40 -03:00
parent f0357964a4
commit d35878415c
3 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,7 @@
# Widget & Property Refactor # Widget & Property Refactor
* Refactor `defaults!` and `properties!` to be proc-macros directly.
- The `macro_rules!` indirection causes the error span to be inside the macro instead of the call site..
* Refactor `#[widget]`. * Refactor `#[widget]`.
- Test build error for parent not a widget. - Test build error for parent not a widget.
- Where is `widget_new!` available for the widget macro? - Where is `widget_new!` available for the widget macro?

View File

@ -335,12 +335,12 @@ impl MultiWhenWgt {
fn on_start(&mut self) { fn on_start(&mut self) {
defaults! { defaults! {
self; self;
util::trace = "default"; util::live_trace = "default";
when *#util::is_state { when *#util::is_state {
util::trace = "state_0"; util::live_trace = "state_0";
} }
when *#util::is_state { when *#util::is_state {
util::trace = "state_1"; util::live_trace = "state_1";
} }
} }
} }

View File

@ -599,6 +599,20 @@ fn prop_assign(prop: &WgtProperty, errors: &mut Errors, is_when: bool) -> TokenS
} }
} }
let ident_meta = ident_spanned!(ident.span()=> "{}_meta__", ident);
let when_check = if is_when {
let meta = quote_call!(#ident_meta());
quote! {
{
let meta__ = #meta
meta__.allowed_in_when_assign();
}
}
} else {
quote!()
};
let prop_init; let prop_init;
match &prop.value { match &prop.value {
@ -625,7 +639,6 @@ fn prop_assign(prop: &WgtProperty, errors: &mut Errors, is_when: bool) -> TokenS
let idents = fields.iter().map(|f| &f.ident); let idents = fields.iter().map(|f| &f.ident);
let values = fields.iter().map(|f| &f.expr); let values = fields.iter().map(|f| &f.expr);
let ident_sorted = ident_spanned!(ident.span()=> "{}_sorted__", ident); let ident_sorted = ident_spanned!(ident.span()=> "{}_sorted__", ident);
let ident_meta = ident_spanned!(ident.span()=> "{}_meta__", ident);
let call = quote_call! { let call = quote_call! {
#ident_sorted(#(#idents_sorted),*) #ident_sorted(#(#idents_sorted),*)
@ -665,6 +678,7 @@ fn prop_assign(prop: &WgtProperty, errors: &mut Errors, is_when: bool) -> TokenS
quote! { quote! {
#attrs { #attrs {
#when_check
#custom_expand #custom_expand
#prop_init #prop_init
} }