fix: incorrect merge logic
This commit is contained in:
parent
988bfc3380
commit
6fb82e13b9
1 changed files with 19 additions and 4 deletions
|
@ -137,7 +137,7 @@ fn derive_impl(input: syn::DeriveInput) -> syn::Result<TokenStream> {
|
|||
|
||||
if field.attrs.iter().any(|attr| attr.path().is_ident("relax")) {
|
||||
// nested
|
||||
Ok(quote! { #vis #name: ::std::option::Option<<#ty as ::relax::Relax>::Partial> })
|
||||
Ok(quote! { #vis #name: ::std::option::Option<<#ty as Relax>::Partial> })
|
||||
} else {
|
||||
// not nested
|
||||
match get_generic_ty("Option", ty) {
|
||||
|
@ -176,10 +176,25 @@ fn derive_impl(input: syn::DeriveInput) -> syn::Result<TokenStream> {
|
|||
})
|
||||
}).collect::<syn::Result<Vec<_>>>()?;
|
||||
|
||||
let merge_fields = fields.iter().map(|field| {
|
||||
let merge_fields = fields.iter().map(|field| -> syn::Result<TokenStream> {
|
||||
let name = field.ident.as_ref();
|
||||
quote! { #name: self.#name.or(optb.#name) }
|
||||
});
|
||||
let nested = field
|
||||
.attrs
|
||||
.iter()
|
||||
.any(|attr| attr.path().is_ident("relax"));
|
||||
|
||||
Ok(match nested {
|
||||
false => quote! { #name: self.#name.or(optb.#name) },
|
||||
true => quote! {
|
||||
#name: match (self.#name, optb.#name) {
|
||||
(::std::option::Option::Some(a), ::std::option::Option::None) => ::std::option::Option::Some(a),
|
||||
(::std::option::Option::None, ::std::option::Option::Some(b)) => ::std::option::Option::Some(b),
|
||||
(::std::option::Option::None, ::std::option::Option::None) => ::std::option::Option::None,
|
||||
(::std::option::Option::Some(a), ::std::option::Option::Some(b)) => ::std::option::Option::Some(a.merge(b)),
|
||||
}
|
||||
}
|
||||
})
|
||||
}).collect::<syn::Result<Vec<_>>>()?;
|
||||
|
||||
Ok(quote! {
|
||||
#(#extra_attrs)*
|
||||
|
|
Loading…
Reference in a new issue