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 fix for #331 continue skips while condition check #332

Merged
merged 4 commits into from
May 10, 2022

Conversation

ahangsu
Copy link
Contributor

@ahangsu ahangsu commented May 10, 2022

Description

The error is caused by https://github.com/algorand/pyteal/blob/master/pyteal/ast/while_.py#L55, where continue block's next block is wired to the start of do block. Expected behavior is wire continue's next to cond's start.

The code incurring bug is

from pyteal import *

i = ScratchVar(slotId=10)
ast = Seq(
    i.store(Int(0)),
    While(i.load() < Int(30)).Do(
        Seq(
            i.store(i.load() + Int(1)),
            Continue(),
        )
    ),
    Return(Int(1))
)

comp = compileTeal(ast, Mode.Application, version=6)

print(comp)

After the bug fix, the (plausibly correct to my eyes) produced code is

#pragma version 6
int 0
store 10
main_l1:
load 10
int 30
<
bz main_l3
load 10
int 1
+
store 10
b main_l1
main_l3:
int 1
return

This PR also contains some testcase change in compiler test, relating with continue in while behavior.

Closes #331

Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

I think this is a great candidate for a graviton test and I'll be very happy to assist in this regard.,

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct, thank you for the fix and updated tests

Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Glad graviton could give greater confidence

@ahangsu ahangsu merged commit 60a04f8 into master May 10, 2022
@ahangsu ahangsu deleted the while-continue-fix branch May 10, 2022 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Continue skips while loop condition check
3 participants