Skip to content

Compiler panic in sema: internal error: entered unreachable code on try new X {} catch {} #1870

@jubnzv

Description

@jubnzv

The compiler panics with internal error: entered unreachable code in src/sema/statements.rs:2358 when a try statement is applied to a new expression whose operand, after stripping the ok-block FunctionCallBlock, is not a FunctionCall / NamedFunctionCall (e.g. a bare identifier).

MRE:

contract C {
    function f() public {
        try new X {} catch {}
    }
}
contract X {}

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

Output:

thread 'main' panicked at src/sema/statements.rs:2358:22:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior: sema emits a diagnostic such as "try only supports external calls or constructor calls" (matching the neighbouring non-new arm) and aborts resolution cleanly.

Also reproduces on --target soroban and --target evm. Solana rejects try earlier, so it is not affected.

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions