Repository navigation
fix(sol-macro-expander): propagate extra_derives to the functions enum - #1124
Merged
Merged
Conversation
The generated function-calls enum (`*Calls`) only derived `Clone`, while the errors and events enums (and the call structs themselves) received the contract-level `#[sol(extra_derives(...))]`. The functions enum was expanded after the expansion context attributes were reset, so the extra derives never reached it. Restore the context attributes after the functions enum is expanded instead of before, so all three enums are expanded consistently. This was flagged in alloy-rs#1011 ("Why not for the functions enum?") and is the cause of #3857. Closes #3857
DaniPopes
approved these changes
Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3857.
Problem
For a contract generated with
#[sol(extra_derives(...))], the function-calls enum (<Name>Calls) only derivedClone. The errors enum, events enum, and the individual call structs all received the user's extra derives, but the calls enum did not — so e.g.Debug/PartialEqcould not be used on it.The cause: in
contract::expand, the expansion context attributes are reset (cx.attrs = prev_cx_attrs) before the functions enum is expanded, but after the errors and events enums. Sincetype_derivesreads the extra derives fromcx.attrs, they never reached the functions enum.This was already noted in #1011:
Fix
Move the context-attribute reset to after the functions enum is expanded, so all three enums (errors, events, functions) are expanded with the contract-level derives in scope. Single-line change plus a clarifying comment.
Tests
Extended
tests/derives.rs::test_extra_derivesto also build the*Callsenum and exerciseDebug/PartialEq/Eq/Hashon it (viaassert_eq!andHashSet). This fails to compile onmain(the calls enum lacks those derives) and passes with the fix.Note
This covers
extra_derives, which is unconditional. Theall_derivesbuiltin-trait set for the calls enum is still subject to the existing per-type capability check (can_derive_builtin_traits), which currently does not resolve the synthetic call-struct types — that is a separate, pre-existing limitation and out of scope here.Verified:
cargo test -p alloy-sol-types --test derives,cargo fmt --check,cargo clippy -p alloy-sol-macro-expanderall pass.