From a26c55653de3c32b897b4899cd73998b79cfadbf Mon Sep 17 00:00:00 2001 From: Pin-Yi Song <611077101@mail.nknu.edu.tw> Date: Tue, 27 May 2025 23:09:54 +0800 Subject: [PATCH] fix: add the condition to fix bug 13029. --- src/Rules/Comparison/MatchExpressionRule.php | 1 + tests/PHPStan/Analyser/AnalyserIntegrationTest.php | 6 ++++++ tests/PHPStan/Analyser/data/bug-13029.php | 14 ++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-13029.php diff --git a/src/Rules/Comparison/MatchExpressionRule.php b/src/Rules/Comparison/MatchExpressionRule.php index 6edef9747b..3cdb31553e 100644 --- a/src/Rules/Comparison/MatchExpressionRule.php +++ b/src/Rules/Comparison/MatchExpressionRule.php @@ -132,6 +132,7 @@ public function processNode(Node $node, Scope $scope): array !$remainingType instanceof NeverType && !$this->isUnhandledMatchErrorCaught($node) && !$this->hasUnhandledMatchErrorThrowsTag($scope) + && !$remainingType->isArray()->yes() ) { $errors[] = RuleErrorBuilder::message(sprintf( 'Match expression does not handle remaining %s: %s', diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index f7f1c22648..2a1f3297fd 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1609,6 +1609,12 @@ public function testBug12979(): void $this->assertNoErrors($errors); } + public function testBug13029(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-13029.php'); + $this->assertNoErrors($errors); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/bug-13029.php b/tests/PHPStan/Analyser/data/bug-13029.php new file mode 100644 index 0000000000..730703f5cc --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-13029.php @@ -0,0 +1,14 @@ + 1, + [false, false] => 0, + [false, true] => -1, +}; \ No newline at end of file