From ddcec756137e8a5b9b9f2d7d39297f46723a50c8 Mon Sep 17 00:00:00 2001 From: Well Date: Sat, 30 Jan 2021 00:58:23 -0300 Subject: [PATCH] Added additional test for the #[property(..)] generator for a currently failing example. --- zero-ui-core/src/lib.rs | 19 ++++++++++++++++++- zero-ui-proc-macros/src/property.rs | 2 +- zero-ui-proc-macros/src/widget_new2.rs | 8 ++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/zero-ui-core/src/lib.rs b/zero-ui-core/src/lib.rs index 46526ce57..9b173b5d0 100644 --- a/zero-ui-core/src/lib.rs +++ b/zero-ui-core/src/lib.rs @@ -681,16 +681,33 @@ mod property_tests { let _ = c; child } + + #[property(context)] + fn not_var_input(child: impl UiNode, input: &'static str) -> impl UiNode { + let _ = input; + child + } } /// Tests on the #[widget(..)] and #[widget_mixin], widget_new! code generators. #[cfg(test)] mod widget_tests { - use crate::{widget2, widget_mixin2, Widget, WidgetId}; + use std::collections::HashSet; + + use crate::{property, state_key, var::Var, widget2, widget_mixin2, UiNode, Widget, WidgetId}; #[widget2($crate::widget_tests::empty_wgt)] pub mod empty_wgt {} + state_key! { + struct TraceKey: HashSet<&'static str>; + } + + #[property(context)] + fn trace(child: impl UiNode, trace: impl Var<&'static str>) -> impl UiNode { + child + } + #[test] pub fn implicit_inherited() { let expected = WidgetId::new_unique(); diff --git a/zero-ui-proc-macros/src/property.rs b/zero-ui-proc-macros/src/property.rs index b1374ee07..7b0446c50 100644 --- a/zero-ui-proc-macros/src/property.rs +++ b/zero-ui-proc-macros/src/property.rs @@ -711,7 +711,7 @@ mod output { let arg_debug_vars = { let ( #(#arg_locals),* ) = self_.unwrap_ref(); Box::new([ - #( + #(// TODO: If the value is not a var the compiler requires a type hint here. See `not_var_input` test. #crate_core::debug::debug_var( #crate_core::var::IntoVar::into_var( std::clone::Clone::clone(#arg_locals) diff --git a/zero-ui-proc-macros/src/widget_new2.rs b/zero-ui-proc-macros/src/widget_new2.rs index 549054e48..0587693ec 100644 --- a/zero-ui-proc-macros/src/widget_new2.rs +++ b/zero-ui-proc-macros/src/widget_new2.rs @@ -107,7 +107,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let mut user_prop_set_calls = vec![]; let mut unset_properties = HashSet::new(); let mut user_properties = HashSet::new(); - + // for each property assigned in the widget instantiation call (excluding when blocks). for up in &user_input.properties { let p_name = util::display_path(&up.path); @@ -143,7 +143,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream { errors.push(format_args!("unknown value `{}!`", sp), sp.span()); } } - + if !user_properties.insert(&up.path) { errors.push(format_args!("property `{}` already set", p_name), up.path.span()); continue; @@ -250,7 +250,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream { wgt_properties .get(&parse_quote! {#p}) .unwrap_or_else(|| non_user_error!("captured property is unknown")) - }); + }); let new_caps = widget_data.new.iter().map(|p| { wgt_properties .get(&parse_quote! {#p}) @@ -258,7 +258,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream { }); let new_child_call = quote! { let node__ = #module::__new_child(#(#new_child_caps),*); - }; + }; let new_call = quote! { #module::__new(node__, #(#new_caps),*) };