Skip to content

fix: resolve compiler panic with large exponent constant rationals#1885

Open
ParthSinghPS wants to merge 1 commit intohyperledger-solang:mainfrom
ParthSinghPS:fix/eval-const-rational-panic
Open

fix: resolve compiler panic with large exponent constant rationals#1885
ParthSinghPS wants to merge 1 commit intohyperledger-solang:mainfrom
ParthSinghPS:fix/eval-const-rational-panic

Conversation

@ParthSinghPS
Copy link
Copy Markdown

Fixes #1881

Description
The compiler was occasionally panicking with Option::unwrap() on a None value in eval_const_rational when a constant with a large scientific-notation exponent (e.g. 0e1000) was used in a rational type context (such as array bounds).

When the parser builds the AST, number_literal() correctly rejects an exponent as too large, leaving the constant variable's initializer as None. However, later evaluations simply used .unwrap() on the initializer. This PR replaces those calls with proper if let Some error handling, returning a Diagnostic instead.

Changes

  • Added missing initializer checks in sema/eval.rs for ConstantVariable evaluation branches.
  • Added a polkadot contract test case large_exponent_const_rational.sol to ensure the compilation errors gracefully rather than crashing.

Signed-off-by: ParthSinghPS <posiedon.1721@gmail.com>
@ParthSinghPS ParthSinghPS force-pushed the fix/eval-const-rational-panic branch from eafca11 to d5e7842 Compare April 22, 2026 19:24
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.

Compiler panic in sema: Option::unwrap() on None in eval_const_rational with large-exponent scientific literal

1 participant