False Positive on Match Arm Comparison with Incremented Bounded Integer
Bug report
Hi,
I encountered a false positive error when using PHPStan with the following code:
<?php /** @param int<0, max> $i */ function foo (int $i): void { echo match ($i++) { 0 => 'zero', default => 'default', }; } foo(0); // prints 'zero'
PHPStan produces the following error:
Match arm comparison between int<1, max> and 0 is always false.
🪪 match.alwaysFalse
However, this should not be the case. The code is correct and the comparison in the match expression should be valid since $i++ starts at 0 and then increments to 1 after the comparison.
It seems PHPStan is not correctly handling the increment operation within the match expression, causing it to misinterpret the possible values of $i.
Please let me know if any further information is needed.
Thank you for your assistance!
Code snippet that reproduces the problem
https://phpstan.org/r/708dfaef-a051-4674-93d0-05d33836639e
Expected output
No error
Did PHPStan help you today? Did it make you happy in any way?
Yes, PHPStan helps catch potential issues early and improves my code quality. Thank you for your hard work!