Skip to content

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

@jubnzv

Description

@jubnzv

The compiler panics with called Option::unwrap() on a None value in src/sema/eval.rs (eval_const_rational) when a constant with a large scientific-notation exponent (e.g. 0e1000) is used in a rational arithmetic expression within a type context (such as an array dimension). eval_const_rational returns None for the oversized literal, and the caller in the subtract path unwraps the result.

MRE:

contract C {
    uint public constant Y = 0e1000;
    constructor(int[Y - .1] memory w) {}
}

Reproduce: save as mre.sol, run solang compile --target polkadot mre.sol.

Output:

thread 'main' panicked at src/sema/eval.rs:NNN:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior: sema rejects the over-sized exponent or the non-integer array dimension with a proper diagnostic instead of panicking.

Reproduces on all targets (solana, polkadot, evm). Threshold is around exponent >= 1000; 0e100 compiles cleanly.

Git commit: 901bfb9
Build: release
rustc 1.96.0-nightly (562dee482 2026-03-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions