diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 653eeaa63..552d99207 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -1582,9 +1582,8 @@ class AssertionFinder $value_right = $conditional->right->expr->value; } if ($right_assignment === true && $positive_right !== null && $value_right !== null) { - $literal_value_comparison = ($value_right + - ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater ? 1 : 0)) * - ($positive_right ? 1 : -1); + $literal_value_comparison = ($positive_right ? 1 : -1) * $value_right + + ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater ? 1 : 0); return self::ASSIGNMENT_TO_RIGHT; } @@ -1606,9 +1605,8 @@ class AssertionFinder $value_left = $conditional->left->expr->value; } if ($left_assignment === true && $positive_left !== null && $value_left !== null) { - $literal_value_comparison = ($value_left + - ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater ? 1 : 0)) * - ($positive_left ? 1 : -1); + $literal_value_comparison = ($positive_left ? 1 : -1) * $value_left + + ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Greater ? -1 : 0); return self::ASSIGNMENT_TO_LEFT; } @@ -1641,10 +1639,8 @@ class AssertionFinder $value_right = $conditional->right->expr->value; } if ($right_assignment === true && $positive_right !== null && $value_right !== null) { - $literal_value_comparison = ($value_right + - ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller ? -1 : 0)) * - ($positive_right ? 1 : -1); - + $literal_value_comparison = ($positive_right ? 1 : -1) * $value_right + + ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller ? -1 : 0); return self::ASSIGNMENT_TO_RIGHT; } @@ -1665,9 +1661,8 @@ class AssertionFinder $value_left = $conditional->left->expr->value; } if ($left_assignment === true && $positive_left !== null && $value_left !== null) { - $literal_value_comparison = $value_left + - ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller ? -1 : 0) * - ($positive_left ? 1 : -1); + $literal_value_comparison = ($positive_left ? 1 : -1) * $value_left + + ($conditional instanceof PhpParser\Node\Expr\BinaryOp\Smaller ? 1 : 0); return self::ASSIGNMENT_TO_LEFT; } diff --git a/tests/IntRangeTest.php b/tests/IntRangeTest.php index e0a8b3ce5..77cc44d98 100644 --- a/tests/IntRangeTest.php +++ b/tests/IntRangeTest.php @@ -45,14 +45,17 @@ class IntRangeTest extends TestCase 'intReduced' => [ '= 500); assert($a < 5000); assert($b >= -5000); - assert($b < -500);', + assert($b < -501); + assert(-60 > $c); + assert(-500 < $c);', 'assertions' => [ '$a===' => 'int<500, 4999>', - '$b===' => 'int<-5000, -499>', + '$b===' => 'int<-5000, -502>', + '$c===' => 'int<-499, -61>', ] ], 'intOperations' => [