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
How to extract nullable type #3623
Comments
This should work but currently doesn't: https://phpstan.org/r/15a41cbf-20e8-409e-898f-19afcf823750 |
Thanks @ondrejmirtes that was my first approach too but yes, not working. I rewrote your example to make it show the problem better (at least to my taste edit: no, I see where yours shows the problem now) : https://phpstan.org/r/38a882d5-d57b-4927-9acd-43a4a0213e99 |
When you say it should work, does it means that if the type of the passed argument is So what happens there is just that |
It has to be accounted for in the bugfix. |
But I am not sure that is correct. For instance imagine another function where edit: or is it correct only because of the |
I’m not sure, that would have to investigated and discussed. |
Ok :) I hope that will interest someone because I do not have the required skills right now :S |
@ondrejmirtes Hmm... I assume this won't be an easy one eh? Ofc it's not just null, the same can be done with other types. So it's most likely a non-trivial generics problem. |
I think it's a matter of touching UnionType::inferTemplateTypes() and UnionType::inferTemplateTypesOn(). And yeah, the logic has to account for some edge cases that need to continue to work... |
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-28: Strict comparison using === between string|null and 1 will always evaluate to false.
-29: Strict comparison using === between A|null and 1 will always evaluate to false.
+28: Strict comparison using === between string and 1 will always evaluate to false.
+29: Strict comparison using === between A and 1 will always evaluate to false. Full report
|
@lud After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-32: Parameter #1 $str of function acceptString expects string, string|null given.
-33: Parameter #1 $str of function acceptString expects string, string|null given.
+32: Parameter #1 $str of function acceptString expects string, string|null given. Full report
|
Fixed: phpstan/phpstan-src@a1b7b38 |
Great, thank you! |
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. |
Hi,
I would like to build this function:
And I would call it like this:
So I would like to write a typespec for the bang function, i.e. transforming a type
?T
intoT
.Is it possible to write such a typespec ?
Thank you.
The text was updated successfully, but these errors were encountered: