Skip to content

Fix incorrect compile_to_assembly call args#1619

Merged
charles-cooper merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:compile-lll-bug
Sep 23, 2019
Merged

Fix incorrect compile_to_assembly call args#1619
charles-cooper merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:compile-lll-bug

Conversation

@iamdefinitelyahuman

Copy link
Copy Markdown
Contributor

The Issue

As discovered by @michwill and reported on Gitter, the following code was not compiling due to an assertion error:

@public    
def g():
    ok: bool = False
    for i in range(5):
        assert ok, "Reasons"

The issue was in vyper/compile_lll.py - several calls to compile_to_assembly were not including the existing_labels argument:

https://github.com/ethereum/vyper/blob/089d0c4046a5e71412b46205788a89e76d7646ea/vyper/compile_lll.py#L273-L275

What I did

Added existing_labels as an argument in compile_to_assembly calls where it was missing.

How to verify it

See the new test cases in tests/parser/features/test_assert.py. I also added checks for proper behavior of the iterated assertions.

Cute Animal Picture

image

@fubuloubu

Copy link
Copy Markdown
Contributor

Would this have been caught with MyPy?

@iamdefinitelyahuman

Copy link
Copy Markdown
Contributor Author

Would this have been caught with MyPy?

Probably - existing_labels is a set, break_dest is a tuple.

@charles-cooper

Copy link
Copy Markdown
Member

Nice fix, thanks. While we're at it, could you please change the assertions to if <fail>: raise CompilerPanic('...')? Apparently some people run python with assertions turned off, plus the CompilerPanic has a more helpful error message.

@charles-cooper charles-cooper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@iamdefinitelyahuman

Copy link
Copy Markdown
Contributor Author

@charles-cooper good call 👍 see new commit

Comment thread vyper/compile_lll.py Outdated
if withargs is None:
withargs = {}
assert isinstance(withargs, dict)
elif not isinstance(withargs, dict):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

kind of a nitpick but to preserve the semantics I think these should be standalone if statements, not elif statements. Somebody could come in later and change the body of the previous branch to read withargs = [] and then we would no longer have the guarantee after this line that withargs is a dict.

Comment thread vyper/compile_lll.py Outdated
if existing_labels is None:
existing_labels = set()
assert isinstance(existing_labels, set)
elif not isinstance(existing_labels, set):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@charles-cooper charles-cooper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, will merge once CI passes

@charles-cooper charles-cooper merged commit efdc6e2 into vyperlang:master Sep 23, 2019
@iamdefinitelyahuman iamdefinitelyahuman deleted the compile-lll-bug branch November 4, 2019 19:45
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.

3 participants