Compiler panic (unreachable!()) in constant folding — bitwise-AND on rational-derived array literal element
Part of #1999 — soroban-emit-multifuzz-v2 campaign tracking issue
Solang version: confirmed on public v0.3.5 CLI (solang compile --target soroban) Target: Soroban Crash type: Rust panic (internal error: entered unreachable code), exit code 101
Summary
An array literal containing a plain integer element alongside an element that mixes decimal multiplication with a bitwise-AND (e.g. 2*2.5+1&1) causes Solang to panic with "internal error: entered unreachable code", during the constant_folding optimization pass, specifically in bigint_to_expression. bigint_to_expression handles exactly 4 type cases (Uint, Int, Bytes, StorageRef) and falls into unreachable!() for anything else. The mixed-type array literal produces a value whose inferred common type (something like an unresolved Rational/decimal-derived type) falls outside those four variants.
Minimal repro
contract Test {
function f() public returns (uint256[] memory) {
uint256[2] memory arr = [1, 2*2.5+1&1];
return arr;
}
}
Root cause
The array literal [1, 22.5+1&1] has mixed element types - one plain integer literal (1) and one decimal-derived expression. When Solidity infers the common type for an array literal with mixed integer/rational elements, it settles on a type (likely Type::Rational or similar "not yet resolved to a concrete int width" type) for the second element, since the 22.5 step is never finalized to a concrete uint/int width before the &1 operation tries to constant-fold it. bigint_to_expression's exhaustive match doesn't account for this intermediate type, hitting unreachable!().
Note
This is one of 5 distinct unreachable!() panic messages found by the same fuzzing campaign, all inside codegen::optimize, suggesting a broader pattern of insufficiently-validated inputs reaching optimization passes that assume "impossible" states. This report covers one specific instance in detail; related unreachable!() messages (should not exist in cfg, : Value, : Void, List and Type Operator shall not appear in the CFG) were also observed and may warrant separate follow-up.
Found via fuzzing
Discovered via AFL++ fuzzing campaign (soroban-emit-multifuzz-v2); confirmed reproducible on Solang v0.3.5.