-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed InterRangeType multiplication/division of maximas by a negative constant #670
Conversation
@@ -232,8 +232,8 @@ public function math($i, $j, $z, $pi, $r1, $r2, $rMin, $rMax, $x, $y) { | |||
assertType('int<-2, 9>|int<21, 30>', $r1 - $z); | |||
assertType('int<-200, -20>|int<1, 30>', $r1 * $z); | |||
assertType('float|int<0, 10>', $r1 / $z); | |||
assertType('int<min, 15>', $rMin * $z); | |||
assertType('int<-100, max>', $rMax * $z); | |||
assertType('int', $rMin * $z); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiplication by $z leads to a integer range with no upper bound unioned with a range without a lower bound. the previous expectation was wrong.
Remaining failures seem unrelated - otherwise good to go |
@@ -1021,12 +1021,7 @@ private function resolveType(Expr $node): Type | |||
} | |||
|
|||
if ($type instanceof IntegerRangeType) { | |||
$negativeRange = $this->resolveType(new Node\Expr\BinaryOp\Mul($node->expr, new LNumber(-1))); | |||
|
|||
if ( $negativeRange instanceof IntegerRangeType && ($negativeRange->getMin() === null || $negativeRange->getMax() === null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was moved into the integerRangeMath method and therefore fixes multiplication with a negative number for the general case
I just added the same patch for division, which initially only was made for multiplication. we could make this even more complete by supporting multiplication/division with negative intervals, e.g. the PR as is already fixes a few glitches, therefore I would like to land it as is. build failures seem unrelated. ready to go. //cc @orklah |
Thank you! |
As discussed in #669 (comment) maxima need to be inverse when multiplying with a negative constant operand
refs phpstan/phpstan#5614
see https://3v4l.org/AUHH7