Skip to content

Commit

Permalink
fix reversed inequality relation used same condition as normal inequa…
Browse files Browse the repository at this point in the history
…lity relation leading to missing errors
  • Loading branch information
kkmuffme committed Mar 18, 2024
1 parent 8e8debc commit 5584673
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -339,13 +339,13 @@ public static function analyze(
&& !$stmt_right_type->isSingle()
&& $left_literal_int_floats !== []
&& (($stmt instanceof PhpParser\Node\Expr\BinaryOp\Greater
&& min($left_literal_int_floats) >= 0)
&& min($left_literal_int_floats) <= 0)
|| ($stmt instanceof PhpParser\Node\Expr\BinaryOp\GreaterOrEqual
&& min($left_literal_int_floats) > 0)
&& min($left_literal_int_floats) < 0)
|| ($stmt instanceof PhpParser\Node\Expr\BinaryOp\Smaller
&& max($left_literal_int_floats) <= 0)
&& max($left_literal_int_floats) >= 0)
|| ($stmt instanceof PhpParser\Node\Expr\BinaryOp\SmallerOrEqual
&& max($left_literal_int_floats) < 0))
&& max($left_literal_int_floats) > 0))
) {
continue;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/BinaryOperationTest.php
Expand Up @@ -1335,6 +1335,14 @@ function foo(string $s1, string $s2): string {
}',
'error_message' => 'PossiblyInvalidOperand',
],
'reverseGreaterEqualMinusOneFalse' => [
'code' => '<?php
$a = $a = rand(0, 1) > 0 ? rand() : false;
if (-1 < $a) {
echo "yes";
}',
'error_message' => 'PossiblyInvalidOperand',
],
'greaterEqualIntNull' => [
'code' => '<?php
$a = $a = rand(0, 1) > 0 ? rand(0, 1000) : null;
Expand Down

0 comments on commit 5584673

Please sign in to comment.