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

Support for non-emptiness check via match (count($array)) #5391

Closed
vudaltsov opened this issue Mar 14, 2021 · 2 comments
Closed

Support for non-emptiness check via match (count($array)) #5391

vudaltsov opened this issue Mar 14, 2021 · 2 comments

Comments

@vudaltsov
Copy link
Contributor

https://psalm.dev/r/95773884b8

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/95773884b8
<?php

/**
 * @return non-empty-array
 */
function test(array $array): array
{
    return match (\count($array)) {
        0 => throw new \InvalidArgumentException,
        default => $array,
    };
}
Psalm output (using commit f1a8407):

INFO: LessSpecificReturnStatement - 8:12 - The type 'array<array-key, mixed>' is more general than the declared return type 'non-empty-array<array-key, mixed>' for test

INFO: MoreSpecificReturnType - 4:12 - The declared return type 'non-empty-array<array-key, mixed>' for test is more specific than the inferred return type 'array<array-key, mixed>'

@weirdan
Copy link
Collaborator

weirdan commented Nov 20, 2022

Fixed (in #7665?)

@weirdan weirdan closed this as completed Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants