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
Type narrowed to non-empty-string is not retained by template #9472
Comments
My guess is that the native type you have on the function disables type inference from the array_map call for that function. |
It works for |
This also applies to union of string literals, eg Simple example: https://phpstan.org/r/529665e1-5525-4b4f-81bf-f1848e852ae8 Our use case where this is often an issue is a generic "tryParse" function: https://phpstan.org/r/12dc41cd-2f6d-4485-ab2c-fdbfb749e067 |
Well, in this case, this is quite a good thing though. Otherwise, it would be impossible to make anything else than an identity function for any generic method allowing scalar types for its bound. |
Closes phpstan/phpstan#8166 Closes phpstan/phpstan#8127 Closes phpstan/phpstan#7944 Closes phpstan/phpstan#7283 Closes phpstan/phpstan#6653 Closes phpstan/phpstan#6196 Closes phpstan/phpstan#9084 Closes phpstan/phpstan#8683 Closes phpstan/phpstan#8074 Closes phpstan/phpstan#7984 Closes phpstan/phpstan#7301 Closes phpstan/phpstan#7087 Closes phpstan/phpstan#5594 Closes phpstan/phpstan#5592 Closes phpstan/phpstan#9472 Closes phpstan/phpstan#9764 Closes phpstan/phpstan#10092
Closes phpstan/phpstan#8166 Closes phpstan/phpstan#8127 Closes phpstan/phpstan#7944 Closes phpstan/phpstan#7283 Closes phpstan/phpstan#6653 Closes phpstan/phpstan#6196 Closes phpstan/phpstan#9084 Closes phpstan/phpstan#8683 Closes phpstan/phpstan#8074 Closes phpstan/phpstan#7984 Closes phpstan/phpstan#7301 Closes phpstan/phpstan#7087 Closes phpstan/phpstan#5594 Closes phpstan/phpstan#5592 Closes phpstan/phpstan#9472 Closes phpstan/phpstan#9764 Closes phpstan/phpstan#10092
Closes phpstan/phpstan#8166 Closes phpstan/phpstan#8127 Closes phpstan/phpstan#7944 Closes phpstan/phpstan#7283 Closes phpstan/phpstan#6653 Closes phpstan/phpstan#6196 Closes phpstan/phpstan#9084 Closes phpstan/phpstan#8683 Closes phpstan/phpstan#8074 Closes phpstan/phpstan#7984 Closes phpstan/phpstan#7301 Closes phpstan/phpstan#7087 Closes phpstan/phpstan#5594 Closes phpstan/phpstan#5592 Closes phpstan/phpstan#9472 Closes phpstan/phpstan#9764 Closes phpstan/phpstan#10092
Last night I came up with the idea that we mostly shouldn't generalize the generic type variables, except when they're in object generics, like Here's the resulting PR: phpstan/phpstan-src#2818 We can't do this for objects, because I want The new behaviour now only applies to bleeding edge (https://phpstan.org/blog/what-is-bleeding-edge) so definitely enable it to get the taste of the future 👍 |
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
Hi there,
In the following snippet, I was expecting the dumped type to be
non-empty-string
, but that is lost somewhere and broadened tostring
Thanks!
Code snippet that reproduces the problem
https://phpstan.org/r/15313fea-5813-4d90-89f9-38f27cba1e32
Expected output
Dumped type: non-empty-string
Did PHPStan help you today? Did it make you happy in any way?
Of course. how did we ever code php without it?
The text was updated successfully, but these errors were encountered: