From fb62e5ec90de7cd41a66c44eab27645b9368680d Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 16 Apr 2021 18:43:37 +0200 Subject: [PATCH] Fix throwpoint in elseif condition --- src/Analyser/NodeScopeResolver.php | 1 + .../Rules/Exceptions/data/unthrown-exception.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 3fa8d0e159..51338b8947 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -712,6 +712,7 @@ private function processStmtNode( $nodeCallback($elseif, $scope); $elseIfConditionType = $condScope->getType($elseif->cond)->toBoolean(); $condResult = $this->processExprNode($elseif->cond, $condScope, $nodeCallback, ExpressionContext::createDeep()); + $throwPoints = array_merge($throwPoints, $condResult->getThrowPoints()); $condScope = $condResult->getScope(); $branchScopeStatementResult = $this->processStmtNodes($elseif, $elseif->stmts, $condResult->getTruthyScope(), $nodeCallback); diff --git a/tests/PHPStan/Rules/Exceptions/data/unthrown-exception.php b/tests/PHPStan/Rules/Exceptions/data/unthrown-exception.php index 4e88111569..f24999a0d2 100644 --- a/tests/PHPStan/Rules/Exceptions/data/unthrown-exception.php +++ b/tests/PHPStan/Rules/Exceptions/data/unthrown-exception.php @@ -121,4 +121,17 @@ public function doAmet2() } } + public function doConsecteur() + { + try { + if (false) { + + } elseif ($this->doAmet()) { + + } + } catch (\InvalidArgumentException $e) { + + } + } + }