From 990887148c85b7cd0887e6ced47255ac6510e544 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 19 May 2022 22:32:14 -0400 Subject: [PATCH] Fix #7968 - combine and simplify types where necessary in ternary analysis --- .../Statements/Expression/TernaryAnalyzer.php | 7 ++++++- tests/TypeReconciliation/TypeAlgebraTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php index 32ad2c5ce..601370e41 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php @@ -129,7 +129,12 @@ class TernaryAnalyzer $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 4930d695a..63a4b41c7 100644 --- a/tests/TypeReconciliation/TypeAlgebraTest.php +++ b/tests/TypeReconciliation/TypeAlgebraTest.php @@ -1202,6 +1202,18 @@ class TypeAlgebraTest extends TestCase if ($foo === null) {} }' ], + 'ternaryAssertionOnBool' => [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.0', + ] ]; }