ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
313 stars 43 forks source link

Clones not being added when passing data to a function #72

Closed ameliatastic closed 1 year ago

ameliatastic commented 1 year ago

Reported in Discord.

The problem is that clones aren't being added in the right spots. Sample code that triggers the error:

@instruction
def ix(sig: Signer, mint: TokenMint, tok: TokenAccount):
    a = array(1, 2, 3)
    steal(a)
    print(a[0])

def steal(arr: Array[i32, 3]):
    pass

When the generated code passes a (which has Rust type Mutable<[i32, 3]>) to steal, a is not cloned.

Making an issue because the error is surprisingly hard to fix elegantly. Can be quickly patched but that would likely cause other problems in "weird" contexts like seed generation. May involve this fix.