IntegerRangeMath: cover more maxima cases#702
Conversation
|
|
||
| assertType('5|10|15|20|30', $x / $y); | ||
|
|
||
| assertType('float|int<0, max>', $rMax / $rMax); |
There was a problem hiding this comment.
There was a problem hiding this comment.
In Psalm I chose not to go this route and just inferred int|float. There's a point where the line is too blurry. In this case, whatever operations or expectation you have that would justify knowing the range will get invalidated by float. You can't deduce the result is an int, nor a float, you can't deduce it's positive.
There was a problem hiding this comment.
I think we'd have to fight current way of working of PHPStan's typesystem to make the result less precise like that. I don't think it's worth it (unless there's a bug stemming from that).
There was a problem hiding this comment.
@ondrejmirtes I'm not sure I understood what you meant by that
There was a problem hiding this comment.
to sum up: the assertion for this line should be changed to float|int ?
There was a problem hiding this comment.
@orklah It's harder for this to make float|int instead of the current result. I'd leave it the same.
There was a problem hiding this comment.
@orklah I mentioned the cast-cases in phpstan/phpstan#5731 (comment)
not sure how hard it would be to get the remaing failing cast-case work though
There was a problem hiding this comment.
well, the current type is also wrong https://phpstan.org/r/b6b8648f-b0a3-4c37-97cf-12ee838d3336
There was a problem hiding this comment.
yep, this case is fixed with this PR, see assertion in line 284
There was a problem hiding this comment.
back to the initial question: IMO this is the most correct type we can expect atm (until phpstan supports float-ranges).
since its also the one which is mathematically correct and we need the implementation lines anayway for the other expectations to pass with this PR, we should merge as is IMO.
| assertType('5|10|15|20|30', $x / $y); | ||
|
|
||
| assertType('float|int<0, max>', $rMax / $rMax); | ||
| assertType('(float|int)', $rMin / $rMin); |
There was a problem hiding this comment.
| * @param int<0, max> $b | ||
| */ | ||
| function divisionLoosesInformation(int $a, int $b): void { | ||
| assertType('float|int<0, max>',$a/$b); |
There was a problem hiding this comment.
|
//cc @orklah ;) |
| * @param int<0, max> $a | ||
| * @param int<0, max> $b | ||
| */ | ||
| function divisionLoosesInformation(int $a, int $b): void { |
There was a problem hiding this comment.
thats the actual case/feature reported/requested in phpstan/phpstan#5731
|
THank you! |
closes phpstan/phpstan#5731