fix: emit diagnostic for unsupported extern fn in const evaluation instead of panicking#9811
Open
orizi wants to merge 1 commit intoorizi/03-31-fix_non_type_numeric_literal_suffixfrom
Conversation
…stead of panicking Fixes #9799
This was referenced Mar 31, 2026
Collaborator
Author
5 tasks
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 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
Replace unreachable panic with proper error reporting when user-defined extern const functions are used in constant expressions.
Type of change
Please check one:
Why is this change needed?
The code previously used
unreachable!()when encountering user-defined extern const functions in constant expressions, which would cause the compiler to panic. This is incorrect behavior as user-defined extern functions should be handled gracefully with a proper diagnostic error rather than crashing the compiler.What was the behavior or documentation before?
When a user-defined extern const function was used in a constant expression, the compiler would panic with an "Unexpected extern function in constant lowering" message.
What is the behavior or documentation after?
The compiler now properly reports error E2127 "This expression is not supported as constant" when encountering user-defined extern const functions in constant expressions, providing a clear diagnostic message to the user instead of crashing.
Related issue or discussion (if any)
Fixes #9799
Additional context
The fix includes a test case that verifies the proper error reporting behavior when
extern const fn f() -> felt252 nopanic;is called within a constant declaration.Note
Low Risk
Low risk: replaces an
unreachable!()panic with a diagnostic and adds a regression test, affecting only const-evaluation error handling.Overview
Fixes constant evaluation to gracefully reject user-defined
extern const fncalls by returningE2127(unsupported constant) instead of hitting anunreachable!()panic.Adds a regression case in
expr/test_data/constantasserting the new diagnostic whenconst X = f();calls a user-definedextern const fn.Written by Cursor Bugbot for commit 6ef9148. This will update automatically on new commits. Configure here.