fix: prevent variable shadowing in event derive macro #9588
+12
−3
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.
Summary
Fixes a variable shadowing issue in the
derive(starknet::Event)macro where struct members namedkeysordatawould collide with the generateddeserializefunction arguments.Type of change
Please check one:
Why is this change needed?
When a user defines a Starknet Event struct with members named
keysordata, the generateddeserializefunction creates local variables with the same names. These local variables shadow theref keysandref dataarguments required for the deserialization process, causing compilation errors or incorrect behavior.By prefixing the local variables for deserialized values (e.g., using
__val_keysinstead ofkeys), this PR ensures that the function arguments remain accessible throughout the function body.What was the behavior or documentation before?
The
derive(starknet::Event)macro generated variable names identical to their struct member names. If a member was namedkeysordata, it would shadow the deserialization buffer argumentskeysanddata.What is the behavior or documentation after?
The macro now generates local variables with a
__val_prefix (e.g.,__val_membername). This prevents any collision with the fixed argument nameskeysanddata, allowing Event structs to safely use these names as member fields.Related issue or discussion (if any)
Additional context