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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template type is not narrowed down in conditional return types #10622
Comments
Even if we eliminate I think we need some logic to make it understand that If you try to use this signature does it work as expected? You can try some |
Yes it works, the return type is narrowed down correctly. But this code is in the stubs, so it throws the same error you see in the playground, when it validates the stub files. For now I'll try to do the same thing with return type extensions. |
When the conditional type is resolved the type is narrowed correctly, but |
I think it could apply the condition in the then branch and apply it inversely in the else branch. So the type in the then branch would be an intersection with the subject type. |
Yep, that's basically what's happening in |
Fixed phpstan/phpstan-src#2948 |
phpstan/phpstan-src@0f2366b Add more tests for issue #10622 phpstan/phpstan-src@ec1209d Merge branch refs/heads/1.10.x into 1.11.x phpstan/phpstan-src@944673f Fix slow enum cases union with lots of cases phpstan/phpstan-src@625298a Merge branch refs/heads/1.10.x into 1.11.x
phpstan/phpstan-src@0f2366b Add more tests for issue #10622 phpstan/phpstan-src@944673f Fix slow enum cases union with lots of cases
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
Hello 馃憢馃徑
I have the following snippet:
I was expecting the
TMapValue
to be narrowed down toModel
instatic<TKey, TMapValue>
because we are in the truthy branch of the if condition. But as it can be seen in the playground, it doesn't work like that.Am I wrong to expect that, or is it a bug?
Code snippet that reproduces the problem
https://phpstan.org/r/92226828-0e09-4210-9906-6b1df14395c0
Expected output
No errors.
Did PHPStan help you today? Did it make you happy in any way?
It helps me every day!
The text was updated successfully, but these errors were encountered: