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
10 changes: 0 additions & 10 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3929,17 +3929,7 @@ private function createConditionalExpressions(
continue;
}

$exprIsGuardExcluded = array_key_exists($exprString, $guardsToExclude);
foreach ($variableTypeGuards as $guardExprString => $guardHolder) {
// A subtype-absorbed target (kept only for re-narrowing) paired with a
// constant-array guard never helps: such a guard represents a unique
// literal value that is not re-asserted as a condition later, yet the
// downstream isSuperTypeOf() guard machinery pays to compare these
// (potentially huge) constant arrays on every branch merge. Skip them.
if ($exprIsGuardExcluded && $guardHolder->getType()->isConstantArray()->yes()) {
continue;
}

if (
array_key_exists($guardExprString, $theirExpressionTypes)
&& $theirExpressionTypes[$guardExprString]->getCertainty()->yes()
Expand Down
35 changes: 35 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14926.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14926;

use function PHPStan\Testing\assertType;

function test_if(?string $x): void
{
if ($x === 'aa') {
$class = ['some_class'];
} elseif ($x === 'bb' || $x === 'cc') {
$class = ['another_class'];
} else {
$class = null;
}
if ($class === null) {
return;
}
assertType("'aa'|'bb'|'cc'", $x);
}

function test_match(?string $x): void
{
$class = match ($x) {
'aa' => ['some_class'],
'bb', 'cc' => ['another_class'],
default => null,
};
if ($class === null) {
return;
}
assertType("'aa'|'bb'|'cc'", $x);
}
Loading