Skip to content

fix: False match.unhandled on array with multiple booleans #4030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Rules/Comparison/MatchExpressionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Analyser/data/bug-13029.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1);

namespace Bug13029;

/** @var bool **/
$bool1 = true;
/** @var bool **/
$bool2 = false;

$x = match([$bool1, $bool2]) {
[true, false], [true, true] => 1,
[false, false] => 0,
[false, true] => -1,
};
Loading