Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,11 @@ private function resolveNormalizedIdentical(Expr\BinaryOp\Identical $expr, Scope

$specifiedTypes = $this->specifyTypesForCountFuncCall($unwrappedLeftExpr, $argType, $rightType, $context, $scope, $expr);
if ($specifiedTypes !== null) {
if ($leftExpr instanceof AlwaysRememberedExpr) {
$funcTypes = $this->create($leftExpr, $rightType, $context, $scope)->setRootExpr($expr)
->unionWith($this->create($unwrappedLeftExpr, $rightType, $context, $scope)->setRootExpr($expr));
return $specifiedTypes->unionWith($funcTypes);
}
return $specifiedTypes;
}

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 @@ -453,6 +453,12 @@ public function testBug13029(): void
$this->analyse([__DIR__ . '/data/bug-13029.php'], []);
}

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

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

declare(strict_types = 1);

namespace Bug12790;

$r = [];
$r[] = 'a';
if (rand(0, 1)) {
$r[] = 'b';
}

echo match (count($r)) {
1 => 'one',
2 => 'two',
};
Loading