Sitelet https://github.com/starkware-libs/cairo/pull/10053
Skip to content

Ignoring later fields instead of overriding when getting dup fields. - #10053

Merged
orizi merged 1 commit into
mainfrom
orizi/06-07-ignoring_later_fields_instead_of_overriding_when_getting_dup_fields
Jun 7, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-07-ignoring_later_fields_instead_of_overriding_when_getting_dup_fields

Conversation

@orizi

@orizi orizi commented Jun 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When a struct has duplicate member names, the first declaration is now preserved instead of being overwritten by the last one. This matches the existing behavior for enum variant redefinition. Additionally, a test expectation for member a's type was corrected from () to core::felt252.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

When a struct member was redefined (declared more than once), the map insertion via insert would overwrite the first declaration with the duplicate. This meant the type and visibility of the last duplicate were retained, even though the duplicate is the one being reported as an error and rejected. This is inconsistent with how enum variant redefinitions are handled.


What was the behavior or documentation before?

On a StructMemberRedefinition error, the last duplicate member's id, ty, and visibility were stored in the members map, discarding the original declaration.


What is the behavior or documentation after?

On a StructMemberRedefinition error, the first (original) member declaration is kept in the members map. The duplicate triggers the diagnostic and is discarded, consistent with enum variant redefinition handling.


Related issue or discussion (if any)

N/A


Additional context

The Entry-based approach (Entry::Vacant / Entry::Occupied) replaces the previous insert-and-check pattern to avoid overwriting the original entry on collision.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi marked this pull request as ready for review June 7, 2026 11:58
@cursor

cursor Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Localized semantic bugfix in struct member collection; diagnostics unchanged, only which member survives duplicates.

Overview
Struct semantic analysis now keeps the first declaration when a member name is duplicated, instead of letting OrderedHashMap::insert replace it with the last duplicate. Duplicates still emit StructMemberRedefinition and are not stored, aligning struct handling with enum variant redefinition.

A structure_test expectation was updated so member a is asserted as core::felt252 (the first field) rather than () (what the old last-wins behavior left in the map).

Reviewed by Cursor Bugbot for commit a274e99. Bugbot is set up for automated code reviews on this repo. Configure here.

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi
orizi enabled auto-merge June 7, 2026 13:24

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi reviewed 1 file.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi
orizi added this pull request to the merge queue Jun 7, 2026
Merged via the queue into main with commit 1364fe0 Jun 7, 2026
54 checks passed
@orizi
orizi deleted the orizi/06-07-ignoring_later_fields_instead_of_overriding_when_getting_dup_fields branch June 7, 2026 14:16
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.

3 participants