Skip to content

Commit 3814348

Browse files
committed
Fix slow analysis on return with a big OR condition
1 parent d462113 commit 3814348

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Analyser/SpecifiedTypes.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
namespace PHPStan\Analyser;
44

55
use PhpParser\Node\Expr;
6+
use PHPStan\Type\GeneralizePrecision;
67
use PHPStan\Type\Type;
78
use PHPStan\Type\TypeCombinator;
9+
use PHPStan\Type\UnionType;
810
use function array_key_exists;
911
use function array_merge;
1012

1113
final class SpecifiedTypes
1214
{
15+
private const MAX_SURE_NOT_TYPES = 8;
1316

1417
private bool $overwrite = false;
1518

@@ -179,6 +182,10 @@ public function unionWith(SpecifiedTypes $other): self
179182
continue;
180183
}
181184

185+
if ($type instanceof UnionType && count($type->getTypes()) >= self::MAX_SURE_NOT_TYPES) {
186+
continue;
187+
}
188+
182189
$sureNotTypeUnion[$exprString] = [
183190
$exprNode,
184191
TypeCombinator::union($type, $other->sureNotTypes[$exprString][1]),

0 commit comments

Comments
 (0)