Union Type with `match (true)` causes wrong type assumption.
Bug report
Maybe related to #7698: Union Type with match (true) causes wrong type assumption.
Code snippet that reproduces the problem
https://phpstan.org/r/f5296bb1-399d-48ee-92c1-0c1ae8eb6e45
Expected output
No error
Did PHPStan help you today? Did it make you happy in any way?
Of course it does 👍
I don't get it - what else can it be besides A and B?
Reduced example: https://phpstan.org/r/aa3d6eea-69cb-421d-8b65-429fb0f30d9b
I don't get it - what else can it be besides A and B?
Not sure, but apparently it now thinks that the second match-arm is always true.
Because it is?
How? Could be both, either A or B, so no error should occur: https://3v4l.org/9Q7G9
As you see, the second match-arm is not true if we call it with test(new A());
You're just misunderstanding the message...
I use true as a condition and either is $t instanceof A or $t instanceof B, but never both. So all correct, there should be no error. So I am not sure how I could misunderstand the message. Care to explain? 😕
BTW, just tested, neither psalm nor phan report an error here. Normally I think phpstan is more accurate, but in this particular case I'm a bit doubtful, no offense of course.
It's the same reason why the same error is reported here: https://phpstan.org/r/a1b566b9-6ed4-46e8-b6b1-db5cf4cf205a
PHPStan wants you to use default instead of $t instanceof B there (only in case you're using strict-rules). But I understand why it might not be always ideal, I've got the idea that the last match arm should not report "always true" situations.
It's the same reason why the same error is reported here: https://phpstan.org/r/a1b566b9-6ed4-46e8-b6b1-db5cf4cf205a
PHPStan wants you to use
defaultinstead of$t instanceof Bthere (only in case you're using strict-rules). But I understand why it might not be always ideal, I've got the idea that the last match arm should not report "always true" situations.
Ah, I think I get it now. Thanks for the reopening though.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.