Skip to content

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
orizi/03-31-fix_non_type_numeric_literal_suffix
Open

fix: emit diagnostic for non-type numeric literal suffix instead of panicking#9810
orizi wants to merge 1 commit intoorizi/03-31-fix_macro_rule_missing_param_kindfrom
orizi/03-31-fix_non_type_numeric_literal_suffix

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Replace panic with proper error handling when encountering non-type identifiers in numeric literal type suffixes. The try_get_ty_by_name function now returns a SemanticDiagnosticKind::NotAType error instead of panicking when a type suffix is not actually a type.


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?

The compiler was panicking when encountering numeric literals with non-type suffixes (e.g., 1_boolean where boolean is 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_boolean as 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_name when a name resolves to a non-type (e.g., an impl or other module item) by returning SemanticDiagnosticKind::NotAType instead.

Adds a new literal diagnostics test ensuring 1_boolean produces error E2011: Not a type rather than crashing.

Written by Cursor Bugbot for commit fca4f70. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@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

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