Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Tealish format error #82

Open
helderjnpinto opened this issue Apr 12, 2023 · 1 comment
Open

[BUG] Tealish format error #82

helderjnpinto opened this issue Apr 12, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@helderjnpinto
Copy link

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 helderjnpinto added the bug Something isn't working label Apr 12, 2023
@fergalwalsh
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants