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

mypyc fails to compile function with multiple return statements #940

Closed
hauntsaninja opened this issue Jul 16, 2022 · 2 comments
Closed
Labels
bug crash Failing compile-time asserts, unhandled exceptions, or generated C code that's blowing up. priority-2-low

Comments

@hauntsaninja
Copy link
Collaborator

Low priority, but ran into this while minimising another failure:

def hmm(self) -> int:
    return 3
    return 2

Gives you:

...
...
  File "/Users/shantanu/dev/mypy/mypyc/irbuild/visitor.py", line 134, in visit_return_stmt
    transform_return_stmt(self.builder, stmt)
  File "/Users/shantanu/dev/mypy/mypyc/irbuild/statement.py", line 74, in transform_return_stmt
    builder.nonlocal_control[-1].gen_return(builder, retval, stmt.line)
  File "/Users/shantanu/dev/mypy/mypyc/irbuild/nonlocalcontrol.py", line 53, in gen_return
    builder.add(Return(value))
  File "/Users/shantanu/dev/mypy/mypyc/irbuild/builder.py", line 205, in add
    return self.builder.add(op)
  File "/Users/shantanu/dev/mypy/mypyc/irbuild/ll_builder.py", line 116, in add
    assert not self.blocks[-1].terminated, "Can't add to finished block"
rep.py:3: AssertionError: Can't add to finished block
@JukkaL JukkaL added bug crash Failing compile-time asserts, unhandled exceptions, or generated C code that's blowing up. labels Jul 16, 2022
@JukkaL
Copy link
Collaborator

JukkaL commented Jul 16, 2022

After we reach an unconditional return statement (or raise, or another unconditional exit from a block), we should stop generating IR.

@ichard26
Copy link
Collaborator

Addressed by python/mypy#16311.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash Failing compile-time asserts, unhandled exceptions, or generated C code that's blowing up. priority-2-low
Projects
None yet
Development

No branches or pull requests

3 participants