-
Notifications
You must be signed in to change notification settings - Fork 653
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
assert that some type is a list #6485
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether a stub would not suffice here. E.g.
/**
* @psalm-assert-if-true list<mixed> $array
*/
function array_is_list(array $array): bool {}
Possibly, but string, bool, array, object are all handled here. I think having it here is less confusing. We could do another PR if we want to migrate everything to stubs though... Or if you want I can migrate all of them in this PR |
Consistency is good, so it should be ok the way it is. Just curious, how hard would it be to use FQNs instead of local names? Because right now Psalm doesn't understand namespace-local overrides of global predicates: https://psalm.dev/r/8d7345506e c.f. https://3v4l.org/4Pko7 |
I found these snippets: https://psalm.dev/r/8d7345506e<?php
namespace NS;
function is_string(mixed $_var): bool { return true; }
function f(mixed $v): string {
if (is_string($v)) {
return $v;
}
return '';
}
var_dump(f(new \stdClass));
|
Oh, this is kinda bad (I'd not feel bad about the fool who did override those with another meaning though!). I wonder if this is fixable in assertions, I'll check |
There's probably a better way to check whether we're using the base function, but I couldn't find it! |
I'll have to check why CI is failing, I'd not expected that |
the CI was failing because I didn't handle the namespace fallback. It's now OK |
…unction doesn't exists in the namespace
will fix an item of #6395