Fix defaulted type parameter. (#2284)

* Fix defaulted type parameter.

* Add test.
This commit is contained in:
Kaede Hoshikawa 2021-12-19 20:46:32 +09:00 committed by GitHub
parent f5b921984a
commit 5b0bbd55c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -192,7 +192,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)>,
}
@ -206,7 +206,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)

View File

@ -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() {}