Skip to content
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

Merged
merged 7 commits into from
Oct 4, 2021
Merged

assert that some type is a list #6485

merged 7 commits into from
Oct 4, 2021

Conversation

orklah
Copy link
Collaborator

@orklah orklah commented Sep 14, 2021

will fix an item of #6395

Copy link
Collaborator

@weirdan weirdan left a 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 {}

@orklah
Copy link
Collaborator Author

orklah commented Sep 16, 2021

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

@weirdan
Copy link
Collaborator

weirdan commented Sep 16, 2021

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

@psalm-github-bot
Copy link

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));
Psalm output (using commit 4eadb73):

ERROR: ForbiddenCode - 14:1 - Unsafe var_dump

@orklah
Copy link
Collaborator Author

orklah commented Sep 16, 2021

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

@orklah orklah marked this pull request as draft September 16, 2021 17:51
@orklah
Copy link
Collaborator Author

orklah commented Sep 16, 2021

There's probably a better way to check whether we're using the base function, but I couldn't find it!

@orklah orklah marked this pull request as ready for review September 16, 2021 21:58
@orklah
Copy link
Collaborator Author

orklah commented Sep 16, 2021

I'll have to check why CI is failing, I'd not expected that

@orklah
Copy link
Collaborator Author

orklah commented Sep 19, 2021

the CI was failing because I didn't handle the namespace fallback. It's now OK

@orklah orklah merged commit 2c72854 into vimeo:master Oct 4, 2021
@weirdan weirdan added the release:feature The PR will be included in 'Features' section of the release notes label Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature The PR will be included in 'Features' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants