Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] sol! fails for structs with UDVT fields #219

Closed
DaniPopes opened this issue Aug 1, 2023 · 0 comments · Fixed by #220
Closed

[Bug] sol! fails for structs with UDVT fields #219

DaniPopes opened this issue Aug 1, 2023 · 0 comments · Fixed by #220
Labels
bug Something isn't working

Comments

@DaniPopes
Copy link
Member

DaniPopes commented Aug 1, 2023

Component

sol! macro

What version of Alloy are you on?

Latest

Operating System

None

Describe the bug

The following code:

sol! {
    type Foo is uint256;
    struct Bar {
        Foo a;
    }
}

Fails with:

error[E0277]: the trait bound `Foo: SolStruct` is not satisfied
   --> crates/sol-types/tests/sol.rs:295:5
    |
295 | /     sol! {
296 | |         type Foo is uint256;
297 | |         struct Bar {
298 | |             Foo a;
299 | |         }
300 | |     }
    | |_____^ the trait `SolStruct` is not implemented for `Foo`
    |
    = note: this error originates in the macro `sol` (in Nightly builds, run with -Z macro-backtrace for more info)

The problem is here:

fn expand_eip712_components(fields: &ast::Parameters<syn::token::Semi>) -> TokenStream {
let bits: Vec<TokenStream> = fields
.iter()
.filter(|f| f.ty.is_custom())
.map(|field| {
let ty = expand_type(&field.ty);
quote! {
components.push(<#ty as ::alloy_sol_types::SolStruct>::eip712_root_type());
components.extend(<#ty as ::alloy_sol_types::SolStruct>::eip712_components());
}
})
.collect();
if bits.is_empty() {
quote! { ::alloy_sol_types::private::Vec::with_capacity(0) }
} else {
quote! {
let mut components = ::alloy_sol_types::private::Vec::new();
#(#bits)*
components
}
}
}

#ty as SolStruct does not hold for UDVTs, which do not implement SolStruct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant