Skip to content

mypyc fails to compile function with multiple return statements #940

@hauntsaninja

Description

@hauntsaninja

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrashFailing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.priority-2-low

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions