Skip to content

fix(sol-macro-expander): propagate extra_derives to the functions enum - #1124

Merged
DaniPopes merged 1 commit into
alloy-rs:mainfrom
satyakwok:fix/calls-enum-extra-derives
Jun 13, 2026
Merged

DaniPopes merged 1 commit into
alloy-rs:mainfrom
satyakwok:fix/calls-enum-extra-derives

Conversation

@satyakwok

Copy link
Copy Markdown
Contributor

Closes #3857.

Problem

For a contract generated with #[sol(extra_derives(...))], the function-calls enum (<Name>Calls) only derived Clone. 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/PartialEq could 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. Since type_derives reads the extra derives from cx.attrs, they never reached the functions enum.

This was already noted in #1011:

@DaniPopes: Why not for the functions enum?

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_derives to also build the *Calls enum and exercise Debug/PartialEq/Eq/Hash on it (via assert_eq! and HashSet). This fails to compile on main (the calls enum lacks those derives) and passes with the fix.

Note

This covers extra_derives, which is unconditional. The all_derives builtin-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-expander all pass.

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
@github-project-automation github-project-automation Bot moved this to Reviewed in Alloy Jun 13, 2026
@DaniPopes
DaniPopes merged commit 6e77545 into alloy-rs:main Jun 13, 2026
31 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in Alloy Jun 13, 2026
@satyakwok
satyakwok deleted the fix/calls-enum-extra-derives branch June 17, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants