Skip to content
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
8 changes: 5 additions & 3 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ public static function remove(Type $fromType, Type $typeToRemove): Type
$fromFiniteTypes = $fromType->getFiniteTypes();
if (count($fromFiniteTypes) > 0) {
$finiteTypesToRemove = $typeToRemove->getFiniteTypes();
if (count($finiteTypesToRemove) === 1) {
if (count($finiteTypesToRemove) > 0) {
$result = [];
foreach ($fromFiniteTypes as $finiteType) {
if ($finiteType->equals($finiteTypesToRemove[0])) {
continue;
foreach ($finiteTypesToRemove as $finiteTypeToRemove) {
if ($finiteType->equals($finiteTypeToRemove)) {
continue 2;
}
}

$result[] = $finiteType;
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ public function testBug9534(): void
]);
}

#[RequiresPhp('>= 8.0')]
public function testBug13029(): void
{
$this->analyse([__DIR__ . '/data/bug-13029.php'], []);
}

#[RequiresPhp('>= 8.0')]
public function testBug11310(): void
{
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-13029.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug13029;

function foo(): void
{
/** @var bool **/
$bool1 = true;
/** @var bool **/
$bool2 = false;

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