solang icon indicating copy to clipboard operation
solang copied to clipboard

Compiler enters unreachable code when building for Solana

Open LucasSte opened this issue 3 years ago • 2 comments

The following contract enters unreachable code when we build it for Solana:

contract testing {
    function doThis(int a) public view returns (int) {
        return a+2;
    }

    function IlikeTests() public returns(function (int) external returns (int) retPtr) {
        function (int) external returns (int) fPtr = this.doThis;

        return fPtr;
    }
}

The error is the following:

thread 'main' panicked at 'internal error: entered unreachable code', src/emit/ethabiencoder.rs:1546:18

LucasSte avatar May 05 '22 15:05 LucasSte

The eth abi encoding does not know how to encode external function types.

This is not easy/possible to implement on Solana. Eth abi encoding encodes this into 32 bytes: 20 bytes for address, and 4 bytes for the function selector. On Solana, we already use 32 bytes for address, so we need to use a different encoding, which won't be compatible with the eth abi encoding libraries. I guess we could encode it as a struct and then specify it as a struct in the abi file.

Once we switch to borsh encoding, this problem goes away.

seanyoung avatar Jun 21 '22 14:06 seanyoung

Once we switch to borsh encoding, this problem goes away.

@seanyoung Yes, this is why I haven't touched this issue.

LucasSte avatar Jun 21 '22 20:06 LucasSte

Closed by #1053

LucasSte avatar Nov 01 '22 19:11 LucasSte