Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sol!)!: gen unit struct for no param events #885

Merged
merged 4 commits into from
Mar 12, 2025

Conversation

yash-atreya
Copy link
Member

Motivation

Closes #879
Stacked over #883

Solution

  • If event does not contain any params, generate a unit struct instead of an empty struct.
sol! {
   event Empty();
}

// New 
pub struct Empty;

// Previous 
pub struct Empty {};

Bindings for events with params remain unchanged.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya changed the title fix(event): gen unit struct for no param events fix(event)!: gen unit struct for no param events Feb 21, 2025
@yash-atreya yash-atreya changed the base branch from main to yash/err-bindings February 21, 2025 08:19
@yash-atreya yash-atreya changed the title fix(event)!: gen unit struct for no param events fix(sol!)!: gen unit struct for no param events Feb 21, 2025
@yash-atreya yash-atreya marked this pull request as ready for review February 21, 2025 08:25
@@ -146,14 +146,24 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, event: &ItemEvent) -> Result<TokenStream>

let alloy_sol_types = &cx.crates.sol_types;

let event_struct = if event.parameters.is_empty() {
quote! {
pub struct #name;
Copy link
Member

Choose a reason for hiding this comment

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

should we derive default in these cases?

Copy link
Member

Choose a reason for hiding this comment

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

No

@DaniPopes

This comment was marked as resolved.

@yash-atreya yash-atreya self-assigned this Feb 24, 2025
@yash-atreya yash-atreya added breaking enhancement New feature or request labels Feb 28, 2025
@yash-atreya yash-atreya merged commit 4db46da into yash/err-bindings Mar 12, 2025
28 of 30 checks passed
@yash-atreya yash-atreya deleted the yash/event-bindings branch March 12, 2025 09:40
yash-atreya added a commit that referenced this pull request Mar 12, 2025
…0/1 param (#883)

* feat(`sol!`)!: generate unit/tuple structs for errors with 0/1 param

* fix

* fix: expand as tuple struct only when param is unnamed

* nit

* FieldKind

* fix

* feat(`sol!`)!: gen unit/tuple structs for call types with 0/1 param (#884)

* feat(`sol!`)!: gen unit/tuple structs for call types with 0/1 param

* fix: expand as tuple struct only if single unnamed param

* fix(`sol!`)!: gen unit struct for no param events (#885)

* expand as unit struct if no params

* nit
@yash-atreya yash-atreya mentioned this pull request Mar 12, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] feat(sol!)!: improve event bindings
3 participants