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

typechecker state committer has incorrect behavior for nested loops #3374

Closed
charles-cooper opened this issue Apr 28, 2023 · 1 comment · Fixed by #3375
Closed

typechecker state committer has incorrect behavior for nested loops #3374

charles-cooper opened this issue Apr 28, 2023 · 1 comment · Fixed by #3375

Comments

@charles-cooper
Copy link
Member

Version Information

What's your issue about?

per @trocher - as of 66930fd, this does not compile:

@external
def foo():
    for i in [1]:
        a:uint256 = i
        b:uint16 = i

while this compiles:

@external
def foo():
    for i in [1]:
        for j in [1]:
            a:uint256 = i
        b:uint16 = i

or this outputs an AssertionError: unreachable, uint256 != uint16:

@external
def foo():
    for i in [1,2,3]:
        for j in [1,2,3]:
            b:uint256 = j + i
        c:uint16 = i

How can it be fixed?

Fill this in if you know how to fix it.

@charles-cooper
Copy link
Member Author

fixed in #3375, see:

iterator_inference_codes = [
"""
@external
def main():
for j in range(3):
x: uint256 = j
y: uint16 = j
""", # issue 3212
"""
@external
def foo():
for i in [1]:
a:uint256 = i
b:uint16 = i
""", # issue 3374
"""
@external
def foo():
for i in [1]:
for j in [1]:
a:uint256 = i
b:uint16 = i
""", # issue 3374
"""
@external
def foo():
for i in [1,2,3]:
for j in [1,2,3]:
b:uint256 = j + i
c:uint16 = i
""", # issue 3374
]
@pytest.mark.parametrize("code", iterator_inference_codes)
def test_iterator_type_inference_checker(namespace, code):
vyper_module = parse_to_ast(code)
with pytest.raises(TypeMismatch):
validate_semantics(vyper_module, {})

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 a pull request may close this issue.

1 participant