tealish icon indicating copy to clipboard operation
tealish copied to clipboard

[BUG] Tealish format error

Open helderjnpinto opened this issue 2 years ago • 1 comments

Describe the bug Using tealish format converts the following code in wrong way

To Reproduce

bytes frc_proofs = Txn.ApplicationArgs[4]
bytes rewards_proof = extract((index * 32), 32, frc_proofs)

with something with this run tealish format approval.tl

and outputs this

bytes frc_proofs = Txn.ApplicationArgs[4]
bytes rewards_proof = extract(<tealish.expression_nodes.Group object at 0x7f8a4e7ec790> 32, frc_proofs)

Expected behavior Just format the code not change the code

helderjnpinto avatar Apr 12 '23 14:04 helderjnpinto

Adding notes from discord: Thanks! It's not just format though. It compiles into extract <tealish.expression_nodes.Group object at 0x1070da8e0> 32 which is obv not valid Teal.

There should actually be a compile time error here because extract expects literals for the first two arguments, not expressions I think you want to use extract3 here: https://tealish.tinyman.org/en/latest/avm.html#extract3 The docs are not clear on what the difference here is unfortunately (auto generated docs limitation :() but I think this should work: extract3(frc_proofs, (index * 32), 32)

Anyway, thanks for the report, I'll figure out what exactly needs to be fixed in Tealish.

Solution

Tealish needs to detect when the args to extract are expressions and use the stack version (extract3) instead of the immediates version. Need to figure out if that can be generalised 🤔

Or just raise an error here because arg1 should be a literal rather than expression?

fergalwalsh avatar Apr 12 '23 14:04 fergalwalsh