Skip to content

Add compiler error when single value event used with multiple data entries#1794

Merged
mootz12 merged 2 commits intomainfrom
harden-single-value-event
Mar 26, 2026
Merged

Add compiler error when single value event used with multiple data entries#1794
mootz12 merged 2 commits intomainfrom
harden-single-value-event

Conversation

@mootz12
Copy link
Copy Markdown
Contributor

@mootz12 mootz12 commented Mar 26, 2026

What

Adds a compiler error during derive_event that informs the user single value events can't have multiple data fields.

Why

The compiler error that surfaced if multiple data fields existed for a single value event was unclear.

error: expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `self`
   --> soroban-sdk/src/tests/contract_event.rs:224:5
    |
224 |     #[contractevent(data_format = "single-value")]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator
    |

The new error is:

error: data_format = "single-value" requires exactly 0 or 1 data fields, but found more
   --> soroban-sdk/src/tests/contract_event.rs:224:5
    |
224 |     #[contractevent(data_format = "single-value")]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

Fixes #1793

Known limitations

None

Copilot AI review requested due to automatic review settings March 26, 2026 13:08
Copy link
Copy Markdown
Contributor

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

Improves the #[contractevent] procedural macro diagnostics by emitting a clear compile-time error when data_format = "single-value" is used with more than one non-topic (“data”) field, addressing the confusing parser error reported in #1793.

Changes:

  • Makes the post-checkpoint darling error accumulator mutable so additional validation errors can be added later in codegen.
  • Adds an explicit validation error for data_format = "single-value" when more than 1 data field is present.

@mootz12 mootz12 requested a review from a team March 26, 2026 13:47
Comment thread soroban-sdk-macros/src/derive_event.rs
@mootz12 mootz12 enabled auto-merge March 26, 2026 15:27
@mootz12 mootz12 added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit f32cd2c Mar 26, 2026
196 of 198 checks passed
@mootz12 mootz12 deleted the harden-single-value-event branch March 26, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contractevent(data_format = "single-value") does not reject multiple data fields

3 participants