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
Constant string param template type is generalized to string #10720
Comments
As always, am happy to fix this myself if pointed in the right direction. 🙂 |
template generalization comes up quite often and it's hard problem to solve as there is no one-size-fits-all solution, take a look at this issue for some more information and possible inspiration for fixing it: |
@mad-briller thanks for the link, seems this might be a bit more complicated than I had initially thought. If I'm understanding the situation correctly it would be quite easy to make my use case work but it may create problems for others as templates might suddenly be stricter than they should be. |
Your specific case is already fixed, if you enable bleeding edge: https://phpstan.org/r/ca05f1e3-d908-48a4-8b1e-5d4006687a97 (I figured out most of "generics generalization" problems are happening inside generic objects - if you were to to something like |
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
It seems that PHPStan generalizes template types somewhat when no clear bound is defined. In my example I pass a constant string which is not empty, a union between this template type and another that is bound to
non-empty-string
should result innon-empty-string
but instead PHPStan reportsstring
Code snippet that reproduces the problem
https://phpstan.org/r/3c8a8a00-c08f-405d-9d98-b603d00b5631
Expected output
No errors.
The
$default
parameter togetOrDefault()
is a constant string in the example, so we know both sides of the return type are not going to be empty.Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: