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

bugfix(lowering): Removed extra diag in cases of out of range u256 match. - #10006

Merged
orizi merged 1 commit into
mainfrom
orizi/05-29-bugfix_lowering_removed_extra_diag_in_cases_of_out_of_range_u256_match
May 31, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/05-29-bugfix_lowering_removed_extra_diag_in_cases_of_out_of_range_u256_match

Conversation

@orizi

@orizi orizi commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When a u256 match arm contains an out-of-range literal (triggering E3009) followed by a wildcard arm, the code previously failed to push a None entry into patterns_on_current_item for the invalid literal case. This broke the one-entry-per-arm invariant, causing the wildcard arm's entry to be misaligned, which produced a spurious E3004 non-exhaustive match error in addition to the legitimate E3009 diagnostic.

The fix adds an else branch that pushes None when handle_u256_literal does not return an inner pattern, preserving the invariant and ensuring only the correct E3009 diagnostic is emitted.


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 u256 pattern literal was out of range, the missing None push caused subsequent arm entries to be offset by one position relative to their expected index. This misalignment made the match appear non-exhaustive even when a wildcard _ arm was present, emitting a false E3004 diagnostic alongside the real E3009.


What was the behavior or documentation before?

A match on u256 with an out-of-range literal followed by a wildcard arm would emit both E3009 (value out of range) and a spurious E3004 (non-exhaustive match).


What is the behavior or documentation after?

The same match now emits only E3009. The wildcard arm is correctly recognized, and no false non-exhaustive diagnostic is produced.


Related issue or discussion (if any)

N/A


Additional context

A new test case Match u256 with out-of-range literal before wildcard is added to the match test data to cover this scenario, verifying that only E3009 appears and no E3004 is emitted.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented May 29, 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 May 29, 2026 16:44
@cursor

cursor Bot commented May 29, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Localized change to match-graph construction for u256 tuple deconstruction; behavior is covered by new lowering test cases.

Overview
Fixes lowering of u256 matches when an arm uses an out-of-range literal during tuple-style deconstruction (low/high).

Previously, a failed handle_u256_literal did not add a per-arm slot, which broke the one-entry-per-arm invariant and could mis-attribute a following _ arm, producing a spurious E3004 alongside E3009.

The change drops unreachable arms (continue on validation failure), tracks survivors in live_filter, and lifts compacted pattern indices back to original arm indices in nested callbacks.

New match graph tests cover out-of-range literal before _ (only E3009) and without wildcard (E3009 + real E3004).

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 842eb7635d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/cairo-lang-lowering/src/lower/flow_control/create_graph/patterns.rs Outdated
@orizi
orizi force-pushed the orizi/05-29-bugfix_lowering_removed_extra_diag_in_cases_of_out_of_range_u256_match branch from 842eb76 to 900dec8 Compare May 30, 2026 09:04

@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 resolved 1 discussion.
Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on eytan-starkware and TomerStarkware).

@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 May 31, 2026 08:23

@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.

@TomerStarkware 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 May 31, 2026
Merged via the queue into main with commit 9f01a03 May 31, 2026
54 checks passed
@orizi
orizi deleted the orizi/05-29-bugfix_lowering_removed_extra_diag_in_cases_of_out_of_range_u256_match branch May 31, 2026 08:42
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