diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php index 32ad2c5ce60..601370e4187 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php @@ -129,7 +129,12 @@ static function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause { $if_clauses = Algebra::simplifyCNF($if_clauses); - $ternary_context_clauses = array_merge($entry_clauses, $if_clauses); + $ternary_context_clauses = $entry_clauses + ? Algebra::simplifyCNF(array_merge( + $entry_clauses, + $if_clauses + )) + : $if_clauses; if ($if_context->reconciled_expression_clauses) { $reconciled_expression_clauses = $if_context->reconciled_expression_clauses; diff --git a/tests/TypeReconciliation/TypeAlgebraTest.php b/tests/TypeReconciliation/TypeAlgebraTest.php index 4930d695aac..63a4b41c77a 100644 --- a/tests/TypeReconciliation/TypeAlgebraTest.php +++ b/tests/TypeReconciliation/TypeAlgebraTest.php @@ -1202,6 +1202,18 @@ function baz(?int $foo): void { if ($foo === null) {} }' ], + 'ternaryAssertionOnBool' => [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.0', + ] ]; }