Skip to content

Commit

Permalink
Fix defaulted type parameter. (yewstack#2284)
Browse files Browse the repository at this point in the history
* Fix defaulted type parameter.

* Add test.
  • Loading branch information
futursolo authored and da-x committed Jul 27, 2022
1 parent b49c6b7 commit 03e785e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/yew-macro/src/function_component.rs
Expand Up @@ -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)>,
}

Expand All @@ -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)
Expand Down
@@ -0,0 +1,25 @@
use yew::prelude::*;

#[derive(Properties, Debug)]
pub struct CompProps<A> {
#[prop_or_default]
_phantom: std::marker::PhantomData<A>,
}

impl<A> PartialEq for CompProps<A> {
fn eq(&self, _rhs: &Self) -> bool {
true
}
}

#[function_component(Comp)]
pub fn comp<A = ()>(_props: &CompProps<A>) -> Html {
todo!()
}

#[function_component(App)]
pub fn app() -> Html {
html! { <Comp /> } // No generics here.
}

fn main() {}

0 comments on commit 03e785e

Please sign in to comment.