fix: handle missing return type context in loop body instead of panicking#9808
Open
orizi wants to merge 1 commit intoorizi/03-31-fix_member_access_on_unreduced_impl_typefrom
Conversation
5 tasks
Collaborator
Author
This was referenced Mar 31, 2026
eytan-starkware
approved these changes
Mar 31, 2026
Contributor
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
TomerStarkware
approved these changes
Apr 1, 2026
Collaborator
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed all commit messages and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on orizi).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixed a panic that occurred when loop expressions were used in fixed-size array size positions by handling the case where no return type context is available and providing appropriate error diagnostics.
Type of change
Please check one:
Why is this change needed?
The compiler was panicking when encountering loop expressions in array size positions because
get_return_type()would returnNone(since loops in array size positions are outside function/loop contexts), but the code was callingunwrap()on thisNonevalue.What was the behavior or documentation before?
The compiler would panic with an unwrap error when processing loop expressions in fixed-size array size positions, preventing proper error reporting.
What is the behavior or documentation after?
The compiler now gracefully handles this invalid usage by using a missing type when no return type context is available, allowing the semantic analysis to continue and report appropriate error diagnostics about type mismatches and invalid array sizes.
Related issue or discussion (if any)
Fixes #9787
Additional context
The fix includes a test case demonstrating the improved error handling for the specific case of
fn f() -> [felt252; for _ in 0..1_u32 {}], which now produces clear error messages instead of panicking.Note
Low Risk
Low risk: a small semantic-analysis guard replaces an
unwrap()with a missing-type fallback, primarily affecting invalid code paths and error reporting.Overview
Prevents a semantic-analysis panic when computing a loop body in contexts without an available return type (e.g. a
forused in fixed-size array size position) by falling back toTypeId::missinginstead ofunwrap().Adds a regression test ensuring this invalid construct no longer crashes and now produces regular diagnostics (type mismatch and invalid fixed-size array size).
Written by Cursor Bugbot for commit b495f1a. This will update automatically on new commits. Configure here.