From 2c3698b8595d075073c375b5972c29716d07f953 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 21 Feb 2026 10:43:20 +0100 Subject: [PATCH] Faster Ternary analysis --- src/Analyser/TypeSpecifier.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Analyser/TypeSpecifier.php b/src/Analyser/TypeSpecifier.php index ad0342b1902..a267f2dd94a 100644 --- a/src/Analyser/TypeSpecifier.php +++ b/src/Analyser/TypeSpecifier.php @@ -1119,14 +1119,20 @@ public function specifyTypesInCondition( return $this->specifyTypesInCondition($scope, $expr->expr, $context)->setRootExpr($expr); } elseif ( $expr instanceof Expr\Ternary - && !$context->null() && !$expr->cond instanceof Expr\Ternary + && !$context->null() ) { - $ifExpr = $expr->if ?? $expr->cond; - $conditionExpr = new BooleanOr( - new BooleanAnd($expr->cond, $ifExpr), - new BooleanAnd(new Expr\BooleanNot($expr->cond), $expr->else), - ); + if ($expr->if !== null) { + $conditionExpr = new BooleanOr( + new BooleanAnd($expr->cond, $expr->if), + new BooleanAnd(new Expr\BooleanNot($expr->cond), $expr->else), + ); + } else { + $conditionExpr = new BooleanOr( + $expr->cond, + new BooleanAnd(new Expr\BooleanNot($expr->cond), $expr->else), + ); + } return $this->specifyTypesInCondition($scope, $conditionExpr, $context)->setRootExpr($expr);