fix(sol-macro): derive builtin traits on overloaded event/error enums#1118
fix(sol-macro): derive builtin traits on overloaded event/error enums#1118pjdurden wants to merge 3 commits into
Conversation
The `*Events` / `*Errors` enum derive computation resolved each variant's type name against the item table to decide whether the `#[sol(all_derives)]` builtin traits (Debug, PartialEq, Eq, Hash) could be derived. Overloaded items get synthetic `_N`-suffixed names (e.g. `Swap_0`, `Swap_1`) that don't resolve as items, so the check fell through to the conservative `false` arm and silently dropped the derives. Compute derivability from the underlying items' parameter types (available when building `ExpandData`) instead of from the synthetic variant type names. Fixes alloy-rs/alloy#3856
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for #[sol(all_derives)] on generated *Calls / *Errors / *Events enums even when variants use overloaded/synthetic names that can’t be resolved for trait-derivability checks.
Changes:
- Add
enum_deriveshelper to applyextra_derives/all_derivesto generated enums. - Precompute
can_derive_builtinfrom underlying parameter types for calls/errors/events expansions. - Add a regression test for overloaded events ensuring the generated
*Eventsenum derives the expected builtin traits.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/sol-types/tests/derives.rs | Adds regression test covering overloaded events + #[sol(all_derives)] on generated events enum. |
| crates/sol-macro-expander/src/expand/mod.rs | Introduces enum_derives helper to derive traits on generated enums using precomputed derivability. |
| crates/sol-macro-expander/src/expand/contract.rs | Computes can_derive_builtin for sets of calls/errors/events and uses enum_derives for enum generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @mattsse , @DaniPopes Let me know if anything is required from my side for this. |
|
Nice — computing from the underlying param types is the cleaner direction here. |
|
Thanks @satyakwok. Resolving the synthetic |
Fixes alloy-rs/alloy#3856
The generated
*Events/*Errorsenum decided whether the#[sol(all_derives)]builtin traits (
Debug,PartialEq,Eq,Hash) could be derived by resolvingeach variant's type name against the item table. Overloaded items get synthetic
_N-suffixed names (Swap_0,Swap_1, …) which don't resolve as items, so thecheck hit the conservative
falsearm and silently dropped the derives — e.g. theUniswap V3 Pool (two
Swapevents) produced aPoolEventsenum that didn't implthe std traits.
Compute derivability from the underlying items' parameter types (available when
building
ExpandData) rather than from the synthetic variant type names. Thefunctions enum is unaffected (contract-level
all_derivesis intentionally notpropagated there).
Added a regression test with overloaded events under
#[sol(all_derives)].