From 55846730e2e0df64dea0c890d855f28f83553c40 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:16:54 +0100 Subject: [PATCH] fix reversed inequality relation used same condition as normal inequality relation leading to missing errors --- .../Analyzer/Statements/Expression/BinaryOpAnalyzer.php | 8 ++++---- tests/BinaryOperationTest.php | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php index cf5802eb6a0..30810f3885c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php @@ -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; } diff --git a/tests/BinaryOperationTest.php b/tests/BinaryOperationTest.php index 54931d748e7..0401f265cb7 100644 --- a/tests/BinaryOperationTest.php +++ b/tests/BinaryOperationTest.php @@ -1335,6 +1335,14 @@ function foo(string $s1, string $s2): string { }', 'error_message' => 'PossiblyInvalidOperand', ], + 'reverseGreaterEqualMinusOneFalse' => [ + 'code' => ' 0 ? rand() : false; + if (-1 < $a) { + echo "yes"; + }', + 'error_message' => 'PossiblyInvalidOperand', + ], 'greaterEqualIntNull' => [ 'code' => ' 0 ? rand(0, 1000) : null;