pyteal icon indicating copy to clipboard operation
pyteal copied to clipboard

Comment as op

Open barnjamin opened this issue 3 years ago • 1 comments
trafficstars

Alternate impl to #407

for Comment(Assert(Int(1)), "yep")

#pragma version 6
int 1
assert
// yep
int 1
return

barnjamin avatar Jun 22 '22 13:06 barnjamin

With this pr, adding comments on asserted expressions, parsing the error msg from algod out, then mapping it back to source teal I get the following output:

Txn WWVF5P2BXRNQDFFSGAGMCXJNDMZ224RJUGSMVPJVTBCVHEZMOMNA had error 'assert failed pc=883' at PC 883 and Source Line 579: 

        store 50
        store 49
        store 48
        store 47
        // correct asset a
        load 50
        txnas Assets
        bytec_0 // "a"
        app_global_get
        ==
        assert          <-- Error
        // correct asset b
        load 51
        txnas Assets
        bytec_1 // "b"
        app_global_get
        ==
        assert
        // correct pool token
        load 49

This is v close to what I think we'd want but the comment is a little far from the actual assert. I think the ideal output is that the comment is on the same line as (or just above) the assert so its easier to see what we're asserting and even provide a friendlier error message on assert. wdyt?

Maybe a different Expr for assert w/ message is warranted?

barnjamin avatar Aug 04 '22 11:08 barnjamin