Skip to content

Incorrect unreachable statement warning #2020

@ndmitchell

Description

@ndmitchell

Describe the Bug

def foo(x):
    for _ in x:
        return 1
    else:
        return 2 # ERROR sandbox.py:5:9-17: This `return` statement is unreachable

print(foo([]))

Python: 3.12

The second return is marked unreachable. The example shows it being reached.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSImMYABGLrgBT4CUiAOujd3bgE40A%2BjQhd8HLjyl8YAFwCufLgEZOUmFDgwJU6XMVcATJ07E%2Bo2Y3pMA2gF0WLEABoQ82dDglyiEAGIaAFUPKAhZUjp5dABjD1x0OBMsal4%2BAFtUWUF0eTTsGD5mRBF0WRYaAFoAPho4WT4dHhkFJTp2EAA5XPyGmmB8AF92zhcQMhkwKFJCWVw0qAoAgAVSCanajBwCGmj4yABzRUyIeMJOAIBlGBgaAAtZWWI4RAB6F-HqKcJ%2BfZeYdBemFw0TgL126AORziANSNFQADdUNBUNhYDs9hBDnxjvEaLhiNCvKZSLJbvEKvCCnATlwALw0doAZkIymMIBGA1cqFiEEpADFoDAKGgsHgiGQQAMgA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

help wantedLarger than "good first issue", but still well-defined and ready for someone to pick uptypechecking

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions