Skip to content

Compiler panic in sema: Option::unwrap() on None for context.function_no when an external call appears in a state-variable initializer #1869

@jubnzv

Description

@jubnzv

The compiler panics with called Option::unwrap() on a None value in src/sema/expression/function_call.rs:2227 when a state-variable initializer contains an external function call (e.g. uint public x = this.foo();). The Solana-target "accounts are required" check unconditionally unwraps context.function_no, but state-variable initializers are resolved at file scope where function_no is None.

MRE:

contract C {
    uint public x = this.foo();
    function foo() external pure returns (uint) { return 1; }
}

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

Output:

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

Expected behavior: sema either rejects external calls in state-variable initializers with a proper diagnostic, or handles the context.function_no == None case in the Solana accounts-required check without unwrapping.

Solana-specific: the crash site lives inside if ns.target == Target::Solana { ... }. Other targets do not hit this path.

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