Skip to content

Commit

Permalink
Fix #7968 - combine and simplify types where necessary in ternary ana…
Browse files Browse the repository at this point in the history
…lysis
  • Loading branch information
muglug committed May 20, 2022
1 parent f960d71 commit 9908871
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/TypeReconciliation/TypeAlgebraTest.php
Expand Up @@ -1202,6 +1202,18 @@ function baz(?int $foo): void {
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',
]
];
}

Expand Down

0 comments on commit 9908871

Please sign in to comment.