Skip to content

[Bug] Missing derive all for events #1133

Closed

Description

@Jinwei1987

Component

contract

What version of Alloy are you on?

1.8.3

Operating System

macOS (Apple Silicon)

Describe the bug

    alloy::sol!(
        #[sol(all_derives)]
        #[sol(extra_derives(serde::Serialize, serde::Deserialize))]
        #[sol(extra_methods)]
        #[sol(abi)]
        #[sol(rpc)]
        Pool,
        "abi/uniswap_v_3/pool.json",
    );

For pool events enum it can't derive std traits. The uniswap v3 pool has two different swap event, which could be the cause.

Activity

  1. added
    bug
    on Mar 31, 2026
  2. satyakwok commented on Jun 11, 2026

    @satyakwok
    Contributor

    Dug into this — the trigger is the two overloaded Swap events, not the field types. Minimal repro (no JSON needed):

    sol! {
        #[sol(all_derives)]
        contract Pool {
            event Swap(address indexed s, uint256 a);
            event Swap(address indexed s, uint256 a, uint256 b);
        }
    }
    // Pool::PoolEvents then lacks Debug / Eq / Hash (PartialEq + Clone are still there).

    A single (non-overloaded) event with the same field types derives fine, so it is specifically the overload.

    Root cause (in sol-macro-expander):

    • For the events enum, ToExpand::Events::to_data sets variants to the overloaded names (overloaded_name, e.g. Swap_0 / Swap_1) and types: None, so generate_enum uses those overloaded idents as the variant types for type_derives.
    • type_derives (all_derives branch) only adds [Debug, PartialEq, Eq, Hash] when can_derive_builtin_traits returns true for every variant type.
    • can_derive_builtin_traits (ty.rs) does Type::Custom(name) => match self.try_item(name), but the overloaded idents (Swap_0) are not registered in all_items (the events live there under the original name Swap), so try_item returns None and it falls through to _ => false.
    • derive_others becomes false, so Debug/Eq/Hash are dropped. Clone/PartialEq survive because they are added by the events path separately, which is why the failure looks partial.

    Same mechanism affects overloaded errors, and it is the same reason the *Calls enum does not pick up all_derives builtin traits (related to alloy-rs/alloy#3857 / alloy-rs/alloy#1124).

    Possible fix directions:

    1. Make can_derive_builtin_traits resolve the overloaded variant name back to the underlying item, or
    2. Compute the enum's derivability from the underlying event/error/function param types (which are available in to_data) instead of re-resolving the synthetic variant idents.

    Happy to put up a PR — do you have a preference between (1) and (2)? I’d lean (2) since it fixes calls/errors/events uniformly without special-casing name resolution.

  3. Jinwei1987 commented on Jun 14, 2026

    @Jinwei1987
    Author
  4. satyakwok commented on Jun 14, 2026

    @satyakwok
    Contributor

    Agreed — that's what #1118 does: it computes the enum's derivability from the underlying param types in one place, instead of re-resolving the synthetic overloaded variant idents. It's approved, so this should be fixed once it lands.

  5. transferred this issue fromalloy-rs/alloyon Jun 30, 2026
  6. moved this from Todo to Done in Alloyon Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions