diff --git a/mypy/checker.py b/mypy/checker.py index 5d243195d50f..3422ef360414 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -477,6 +477,8 @@ def check_first_pass(self) -> None: if not self.is_noop_for_reachability(d): self.msg.unreachable_statement(d) break + else: + self.accept(d) else: self.accept(d) @@ -2791,6 +2793,8 @@ def visit_block(self, b: Block) -> None: if not self.is_noop_for_reachability(s): self.msg.unreachable_statement(s) break + else: + self.accept(s) else: self.accept(s) diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index b8b438b979c6..0d1408bddd9e 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -1494,3 +1494,11 @@ from typing import Generator def f() -> Generator[None, None, None]: return None yield None + +[case testErrorInNoopForReachabilityStatement] +# flags: --warn-unreachable +def double(x: int) -> int: + if not isinstance(x, int): + raise BaseException["Expected an integer"] # E: The type "Type[BaseException]" is not generic and not indexable + return x +[builtins fixtures/tuple.pyi]