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

fix(semantic): don't ICE on a wrong generic-argument count through a local use alias - #10211

Merged
orizi merged 1 commit into
mainfrom
orizi/07-18-fix_semantic_don_t_ice_on_a_wrong_generic-argument_count_through_a_local_use_alias
Jul 19, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/07-18-fix_semantic_don_t_ice_on_a_wrong_generic-argument_count_through_a_local_use_alias

Conversation

@orizi

@orizi orizi commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Propagates errors from specialize_generic_module_item in specialize_generic_inner_item by changing the return type from ResolvedConcreteItem to Maybe<ResolvedConcreteItem> and using ? instead of .unwrap(). Call sites are updated to propagate the error with ?. A regression test is added covering the case where a local use alias is instantiated with the wrong number of generic arguments (e.g., use Pair as P; P::<felt252, u8, u16> { ... }).


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 local use alias was instantiated with the wrong number of generic arguments, specialize_generic_module_item returned an Err, but the call in specialize_generic_inner_item called .unwrap() on that result, causing an ICE (internal compiler error) instead of a proper diagnostic.


What was the behavior or documentation before?

Providing the wrong number of generic arguments to a type accessed through a local use alias (e.g., use Pair as P; P::<felt252, u8, u16> { ... }) triggered an ICE rather than emitting a diagnostic error.


What is the behavior or documentation after?

The compiler now correctly emits a diagnostic error (E2163: Expected 2 generic arguments, found 3.) and no longer panics in this case.


Related issue or discussion (if any)

N/A


Additional context

The fix is minimal: replacing .unwrap() with ? and adjusting the return type of specialize_generic_inner_item accordingly.

…local use alias

`specialize_generic_statement_arg` unwrapped the `Maybe` returned by
`specialize_generic_module_item`, which errors on e.g. `TooManyGenericArguments`.
Every sibling resolution path propagates that error with `?`; only the
statement-`use` path (`ResolvedBase::StatementEnvironment`) unwrapped, so
`use Pair as P; P::<felt252, u8, u16> { .. }` panicked instead of emitting E2163.

Return `Maybe` and propagate with `?`.
@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jul 18, 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 July 18, 2026 10:10
@cursor

cursor Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Small error-propagation change in semantic path resolution; no auth, data, or API surface changes beyond replacing a panic with an existing diagnostic path.

Overview
Fixes an ICE when a type reached through a local use alias is given the wrong number of generic arguments (e.g. use Pair as P; P::<felt252, u8, u16> { ... }).

specialize_generic_statement_arg now returns Maybe<ResolvedConcreteItem> and forwards failures from specialize_generic_module_item with ? instead of .unwrap(). Concrete path resolution for statement-environment items propagates those errors the same way module items already did.

A diagnostic regression test expects E2163 (wrong generic argument count) instead of a compiler panic.

Reviewed by Cursor Bugbot for commit 53098f7. 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 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi
orizi added this pull request to the merge queue Jul 19, 2026
Merged via the queue into main with commit 080a411 Jul 19, 2026
55 checks passed
@orizi
orizi deleted the orizi/07-18-fix_semantic_don_t_ice_on_a_wrong_generic-argument_count_through_a_local_use_alias branch July 19, 2026 16:13
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