Skip to content

Commit

Permalink
Fix #3932 - try to get assertions of negated expression if instant ne…
Browse files Browse the repository at this point in the history
…gation fails
  • Loading branch information
muglug committed Aug 5, 2020
1 parent e808391 commit e0f5595
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ public static function analyze(
try {
$negated_left_clauses = Algebra::negateFormula($left_clauses);
} catch (\Psalm\Exception\ComplicatedExpressionException $e) {
return false;
try {
$negated_left_clauses = Algebra::getFormula(
\spl_object_id($stmt->left),
new PhpParser\Node\Expr\BooleanNot($stmt->left),
$context->self,
$statements_analyzer,
$codebase,
false
);
} catch (\Psalm\Exception\ComplicatedExpressionException $e) {
return false;
}
}

if ($left_context->reconciled_expression_clauses) {
Expand Down
1 change: 0 additions & 1 deletion tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,6 @@ function assertArrayWithOffset($decoded): array {
],
'avoidOOM' => [
'<?php
/** @psalm-suppress MixedInferredReturnType */
function gameOver(
int $b0,
int $b1,
Expand Down
21 changes: 21 additions & 0 deletions tests/TypeReconciliation/TypeAlgebraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,27 @@ function formatRange(?A $from, ?A $to): void {
$to->foo();
}',
],
'testSimplishThing' => [
'<?php
function foo(
bool $a,
bool $b,
bool $c,
bool $d,
bool $e,
bool $f,
bool $g,
bool $h,
bool $i,
bool $j
): bool {
return ($a && $b)
|| ($c && $d)
|| ($e && $f)
|| ($g && $h)
|| ($i && $j);
}'
],
];
}

Expand Down

0 comments on commit e0f5595

Please sign in to comment.