1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #7968 - combine and simplify types where necessary in ternary analysis

This commit is contained in:
Matt Brown 2022-05-19 22:32:14 -04:00
parent f960d71b7e
commit 990887148c
2 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -1202,6 +1202,18 @@ class TypeAlgebraTest extends TestCase
if ($foo === null) {}
}'
],
'ternaryAssertionOnBool' => [
'code' => '<?php
function test(string|object $s, bool $b) : string {
if (!$b || is_string($s)) {
return $b ? $s : "";
}
return "";
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
]
];
}