Skip to content

Conversation

squadgazzz
Copy link
Contributor

@squadgazzz squadgazzz commented Sep 18, 2025

Motivation

Fixes #1009, which shows that currently all_derives and extra_derives don't propagate to periphery SC structs, such as errors and events.

Solution

Do not clean the context attributes before configuring bindings for periphery structs, and do that only afterward. Function enum is not affected, since it doesn't make much sense to propagate derives there.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@squadgazzz squadgazzz marked this pull request as ready for review September 18, 2025 08:01
@Copilot Copilot AI review requested due to automatic review settings September 18, 2025 08:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where all_derives and extra_derives attributes weren't propagating to periphery Solidity contract structs like events and errors. The solution delays the cleanup of context attributes until after generating the event and error enums, ensuring they inherit the contract-level derive configurations.

Key changes:

  • Move context attributes cleanup (cx.attrs = prev_cx_attrs) after error and event enum generation
  • Create separate enum expanders for errors and events while context still has derive attributes
  • Move function enum generation after cleanup since function enums don't need derive propagation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/sol-types/tests/derives.rs Comprehensive test cases validating that all_derives and extra_derives propagate to events and errors
crates/sol-macro-expander/src/expand/contract.rs Implementation changes to delay context cleanup and ensure derive propagation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@squadgazzz squadgazzz changed the title Propagate all_derives and extra_derives to periphery SC structs fix(sol-macro-expander): propagate all_derives and extra_derives to periphery SC structs Sep 18, 2025
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, lgtm

this could be problematic for users that currently implement these manually as a workaround but imo we should just derive these

pending @DaniPopes

Comment on lines +187 to +194
let functions_enum = (!functions.is_empty()).then(|| {
let mut attrs = enum_attrs;
let doc_str = format!("Container for all the [`{name}`](self) function calls.");
attrs.push(parse_quote!(#[doc = #doc_str]));
attrs.push(parse_quote!(#[derive(Clone)]));
let enum_expander = CallLikeExpander { cx, contract_name: name.clone(), extra_methods };
enum_expander.expand(ToExpand::Functions(&functions), attrs)
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this just moves the location and add thes derives

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it uses the flushed cx.

@github-project-automation github-project-automation bot moved this to Reviewed in Alloy Sep 18, 2025
@squadgazzz
Copy link
Contributor Author

@DaniPopes could you please review this small PR? 🙏

@DaniPopes
Copy link
Member

Why not for the functions enum?

@squadgazzz
Copy link
Contributor Author

Why not for the functions enum?

This gets ignored anyway, I already don't remember where exactly, sorry. And I can't think of any use case for debugging or comparing function enums.

@squadgazzz
Copy link
Contributor Author

@mattsse may i ask you to merge it?

@mattsse mattsse merged commit fad2642 into alloy-rs:main Sep 23, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Reviewed to Done in Alloy Sep 23, 2025
squadgazzz added a commit to squadgazzz/core that referenced this pull request Sep 25, 2025
…erives` to periphery SC structs (alloy-rs#1011)"

This reverts commit fad2642.
This was referenced Sep 25, 2025
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.

[Bug] extra_derives doesn't apply to periphery structs

3 participants