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

psalm-assert for non-empty-list broken since 3.8.2 #2649

Closed
tux-rampage opened this issue Jan 17, 2020 · 2 comments
Closed

psalm-assert for non-empty-list broken since 3.8.2 #2649

tux-rampage opened this issue Jan 17, 2020 · 2 comments

Comments

@tux-rampage
Copy link
Contributor

The following code used to work and now errors incorrectly: https://psalm.dev/r/b3ecdd7b42

It seems that the non-empty-list assertion incorrectly infers list<mixed> instead of non-empty-list<mixed>.

<?php
  
/**
 * @psalm-pure
 * @psalm-assert non-empty-list $array
 * @param mixed  $array
 * @throws InvalidArgumentException
 */
function isNonEmptyList($array, string $message = ''): void
{
  // ...
}

/**
 * @psalm-pure
 * @psalm-param mixed $value
 * @psalm-return non-empty-list<mixed>
 */
function consume($value): array
{
    isNonEmptyList($value);
    return $value;
}
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/b3ecdd7b42
<?php
  
/**
 * @psalm-pure
 * @psalm-assert non-empty-list $array
 *
 * @param mixed  $array
 *
 * @throws InvalidArgumentException
 */
function isNonEmptyList($array, string $message = ''): void
{
  // ...
}

/**
 * @psalm-pure
 *
 * @psalm-param mixed $value
 *
 * @psalm-return non-empty-list<mixed>
 */
function consume($value): array
{
    isNonEmptyList($value);
    return $value;
}
Psalm output (using commit c50fa27):

INFO: UnusedParam - 11:25 - Param $array is never referenced in this method

INFO: UnusedParam - 11:40 - Param $message is never referenced in this method

ERROR: InvalidReturnStatement - 26:12 - The type 'list<mixed>' does not match the declared return type 'non-empty-list<mixed>' for consume

ERROR: InvalidReturnType - 21:18 - The declared return type 'non-empty-list<mixed>' for consume is incorrect, got 'list<mixed>'

@smoench
Copy link

smoench commented Jan 17, 2020

duplicate of #2636 which has been resolved in master :-)

@muglug muglug closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants