Skip to content

Compiler panic in codegen: unreachable!("This type cannot be encoded") when abi-encoding an internal function reference #1862

@jubnzv

Description

@jubnzv

The compiler panics with internal error: entered unreachable code: This type cannot be encoded in src/codegen/encoding/mod.rs:1453 when an internal function reference is passed to abi.encode or abi.encodePacked. Sema only rejects mapping and recursive argument types for the variadic abi.encode* family, so Type::InternalFunction slips through to the encoder where it is explicitly listed as unreachable.

MRE:

contract Foo {
    function f() public {
        abi.encodePacked(f);
    }
}

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

Output:

thread 'main' panicked at src/codegen/encoding/mod.rs:1453:36:
internal error: entered unreachable code: This type cannot be encoded
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior: sema rejects internal function references in abi.encode* arguments with a proper diagnostic.

Also reproduces on --target evm and --target solana. abi.encode(f) triggers the symmetric panic at src/codegen/encoding/mod.rs:291.

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