Skip to content

Commit 2bce860

Browse files
committed
Oh, add a test too!
1 parent 83744d3 commit 2bce860

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

mypy/checker.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,11 @@ def check_first_pass(self, recurse_into_functions: bool = True) -> None:
613613
marked_unreachable = True
614614
if not self.should_report_unreachable_issues():
615615
finish = True
616-
if not self.is_noop_for_reachability(d) and not reported_unreachable:
616+
if (
617+
not self.is_noop_for_reachability(d)
618+
and not reported_unreachable
619+
and not finish
620+
):
617621
self.msg.unreachable_statement(d)
618622
finish = True
619623
reported_unreachable = True
@@ -3321,7 +3325,11 @@ def visit_block(self, b: Block) -> None:
33213325
marked_unreachable = True
33223326
if not self.should_report_unreachable_issues():
33233327
finish = True
3324-
if not self.is_noop_for_reachability(s) and not reported_unreachable:
3328+
if (
3329+
not self.is_noop_for_reachability(s)
3330+
and not reported_unreachable
3331+
and not finish
3332+
):
33253333
self.msg.unreachable_statement(s)
33263334
finish = True
33273335
reported_unreachable = True

test-data/unit/check-unreachable-code.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,3 +1744,10 @@ assert sys.platform == "win32"
17441744

17451745
42 + "no way" # type: ignore[operator]
17461746
[builtins fixtures/isinstancelist.pyi]
1747+
1748+
1749+
[case testCheckUnreachableBasics]
1750+
# flags: --check-unreachable --warn-unreachable
1751+
if False:
1752+
reveal_type(5) # E: Statement is unreachable \
1753+
# N: Revealed type is "Literal[5]?"

0 commit comments

Comments
 (0)