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
array_pop output should not be null given a full array #1722
Comments
This falls under dependent types, here are other examples: https://github.com/phpstan/phpstan/milestone/12 I'm not sure if it's worth tackling since the code is really analyser-unfriendly. I have no idea right now how I would model it and approach this problem. |
I don't either. Here's where I use this pattern. Easy obvious workaround is to assert |
I don't see any reason to support this. Statically & strictly typed language don't to this either. |
That in itself shouldn't be an argument, I don't think. For example, those tools generally do not allow this code: function takesObject(object $_o): void {}
function foo(?object $a, ?object $b): void {
if ($a || $b) {
if ($a) {
$c = $a;
} else {
$c = $b;
}
takesObject($c);
}
} But with the right analysis a tool can understand what's happening: https://getpsalm.org/r/680d27b861 |
Fixed the issue in the OP: https://phpstan.org/r/14f773c7-b8fd-4666-b0d2-5f6ba10037cf I'll keep track of #1722 (comment) to do it later :) Fixed by: phpstan/phpstan-src@a9d5c8b |
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. |
Found this while deciding whether to add similar functionality in another package.
Expected: no issue
Actual:
Function foo() should return int but returns int|null
https://phpstan.org/r/693d212d-fec7-45fd-bce5-7bcf7c01afff
The text was updated successfully, but these errors were encountered: