You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To me, there are 2 issues, but one is linked to the other.
The first issue is the visible one, that PHPStan yells that a division per 0 may occur while it's not possible thanks to the ternary check.
The second issue is hidden in the fact that doing $int += bool is wrongly interpreted as $int to be 0|1 while it's actually int (type can be narrowed depending on the context).
The point is I don't want to add this cast because it shouldn't be mandatory here. PHP Infection could create any mutant that removes the cast and my unit-tests will still pass, without any way for me to kill that mutant and to keep the cast.
I think that solving the wrong interpretation of $int += bool could change the dumpType of it, and it will fix the visible error reported by PHPStan in my first example.
The text was updated successfully, but these errors were encountered:
@@ @@+ 9: Only numeric types are allowed in +, bool given on the right side.+10: Only numeric types are allowed in +, bool given on the right side.
13: Dumped type: 0|1
14: Dumped type: 0|1
17: Binary operation "/" between 0|1 and 0|1|2 results in an error.
Full report
Line
Error
9
Only numeric types are allowed in +, bool given on the right side.
10
Only numeric types are allowed in +, bool given on the right side.
The bug I encounter is a little bit hard to explain so this snippet is better than a long text: https://phpstan.org/r/13f4b1df-ce73-4db0-849c-ec6369ac75d9
To me, there are 2 issues, but one is linked to the other.
The first issue is the visible one, that PHPStan yells that a division per 0 may occur while it's not possible thanks to the ternary check.
The second issue is hidden in the fact that doing
$int += bool
is wrongly interpreted as$int
to be0|1
while it's actuallyint
(type can be narrowed depending on the context).For instance, if I try with my boolean checks type-casted to
(int)
, there are no more errors: https://phpstan.org/r/ac373a15-f927-43b3-bd3c-101cffb49599The point is I don't want to add this cast because it shouldn't be mandatory here. PHP Infection could create any mutant that removes the cast and my unit-tests will still pass, without any way for me to kill that mutant and to keep the cast.
I think that solving the wrong interpretation of
$int += bool
could change the dumpType of it, and it will fix the visible error reported by PHPStan in my first example.The text was updated successfully, but these errors were encountered: