From 03e785e8250b1581404eed18c96f9aaf9c1f1964 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sun, 19 Dec 2021 20:46:32 +0900 Subject: [PATCH] Fix defaulted type parameter. (#2284) * Fix defaulted type parameter. * Add test. --- packages/yew-macro/src/function_component.rs | 4 +-- .../with-defaulted-type-param-pass.rs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 packages/yew-macro/tests/function_component_attr/with-defaulted-type-param-pass.rs diff --git a/packages/yew-macro/src/function_component.rs b/packages/yew-macro/src/function_component.rs index e21893b35b4..f05ed2b2428 100644 --- a/packages/yew-macro/src/function_component.rs +++ b/packages/yew-macro/src/function_component.rs @@ -201,7 +201,7 @@ pub fn function_component_impl( #[doc(hidden)] #[allow(non_camel_case_types)] #[allow(unused_parens)] - #vis struct #function_name #impl_generics { + #vis struct #function_name #generics { _marker: ::std::marker::PhantomData<(#phantom_generics)>, } @@ -215,7 +215,7 @@ pub fn function_component_impl( #(#attrs)* #[allow(type_alias_bounds)] - #vis type #component_name #impl_generics = ::yew::functional::FunctionComponent<#function_name #ty_generics>; + #vis type #component_name #generics = ::yew::functional::FunctionComponent<#function_name #ty_generics>; }; Ok(quoted) diff --git a/packages/yew-macro/tests/function_component_attr/with-defaulted-type-param-pass.rs b/packages/yew-macro/tests/function_component_attr/with-defaulted-type-param-pass.rs new file mode 100644 index 00000000000..9ff37a91496 --- /dev/null +++ b/packages/yew-macro/tests/function_component_attr/with-defaulted-type-param-pass.rs @@ -0,0 +1,25 @@ +use yew::prelude::*; + +#[derive(Properties, Debug)] +pub struct CompProps { + #[prop_or_default] + _phantom: std::marker::PhantomData, +} + +impl PartialEq for CompProps { + fn eq(&self, _rhs: &Self) -> bool { + true + } +} + +#[function_component(Comp)] +pub fn comp(_props: &CompProps) -> Html { + todo!() +} + +#[function_component(App)] +pub fn app() -> Html { + html! { } // No generics here. +} + +fn main() {}