fix: emit diagnostic for non-type numeric literal suffix instead of panicking#9810
Open
orizi wants to merge 1 commit intoorizi/03-31-fix_macro_rule_missing_param_kindfrom
Conversation
This was referenced Mar 31, 2026
Collaborator
Author
This was referenced Mar 31, 2026
This was referenced Mar 31, 2026
eytan-starkware
requested 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: all files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).
crates/cairo-lang-semantic/src/expr/test_data/literal line 36 at r1 (raw file):
//! > expected_diagnostics error[E2011]: Not a type.
Bad diagnostic
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 panic with proper error handling when encountering non-type identifiers in numeric literal type suffixes. The
try_get_ty_by_namefunction now returns aSemanticDiagnosticKind::NotATypeerror instead of panicking when a type suffix is not actually a type.Type of change
Please check one:
Why is this change needed?
The compiler was panicking when encountering numeric literals with non-type suffixes (e.g.,
1_booleanwherebooleanis not a valid type). This caused the compiler to crash instead of providing a proper diagnostic message to the user.What was the behavior or documentation before?
When a numeric literal had a suffix that wasn't a valid type, the compiler would panic with a message like "boolean is not a type."
What is the behavior or documentation after?
The compiler now gracefully handles this error case by emitting a proper diagnostic error "Not a type." (error code E2011) and continues compilation instead of crashing.
Related issue or discussion (if any)
Fixes #9791
Additional context
The change includes a test case that verifies the new error handling behavior with
1_booleanas an example of a numeric literal with an invalid type suffix.Note
Low Risk
Low risk: replaces a panic with returning
SemanticDiagnosticKind::NotAType, primarily affecting error reporting paths and covered by a new regression test.Overview
Prevents a panic in
try_get_ty_by_namewhen a name resolves to a non-type (e.g., an impl or other module item) by returningSemanticDiagnosticKind::NotATypeinstead.Adds a new literal diagnostics test ensuring
1_booleanproduces errorE2011: Not a typerather than crashing.Written by Cursor Bugbot for commit fca4f70. This will update automatically on new commits. Configure here.