Search code examples
llvmsoliditysolana

Solang compiler fails when sending lamports within a loop (targeting Solana)


I'm building a Solana program to manage payments to multiple accounts, however the compiler fails whenever a .send() call is made within a loop. For example, the following code compiles just fine:

function send( address[3] memory receivers ) external payable {
    require(payable(receivers[0]).send(uint64(5)), "Transaction failed");
}

But the following code throws an error:

function send( address[3] memory receivers ) external payable {
    for (uint i = 0; i < receivers.length; i++) {
      require(payable(receivers[i]).send(uint64(5)), "Transaction failed");
    }
}

LLVM ERROR: Unsupported dynamic stack allocation

I've also tried using .transfer() and .call(), all throw the same error. Is this behavior unsupported or is there a way I can resolve this issue?


Solution

  • This is an issue in solang v0.1.9. It should compile fine with solang latest main.

    We should be release solang v0.1.10 shortly.