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
string is incorrectly narrowed down in if with and + or conditions #6329
Comments
Don't know why it gets lost but it can definitely be solved. |
Feel free to add the info where you are expecting the problem to be, if you think it's easy enough for others to solve :) I can try to take a look at it myself. |
BooleanOr type narrowing is handled here in TypeSpecifier, sho that's where step debugging should begin: https://github.com/phpstan/phpstan-src/blob/b5e71db32dfd256174290b243d72cefd15768503/src/Analyser/TypeSpecifier.php#L709-L725 |
To sum up what I found out in a time-boxed debugging session: |
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. |
Bug report
PHPStan seems to be having problems narrowing down types in more complex if statements. In the case I added I use
is_string
and checks againstnull
and''
to determine that this is anon-empty-string|null
type. In a case it is wrongfully detected asstring|null
though. The example makes more sense than me here I guess :)Could just be a limitation of PHPStan's capabilities with ifs, feel free to close then.
Code snippet that reproduces the problem
https://phpstan.org/r/ae139617-651e-4a89-8e13-824f9ce1a511
Expected output
No errors
Did PHPStan help you today? Did it make you happy in any way?
Always :)
The text was updated successfully, but these errors were encountered: