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-param array<string> does not work with @psalm-assert non-empty-list #3906
Labels
Comments
I found these snippets: https://psalm.dev/r/9d7436fe23<?php
class Assert {
/**
* @psalm-assert non-empty-list $array
*
* @param mixed $array
* @param string $message
*
* @throws InvalidArgumentException
*/
public static function isNonEmptyList($array, $message = ''): void
{
}
}
/**
* @psalm-param list<string> $values
*/
function consume(array $values): void
{
Assert::isNonEmptyList($values);
}
|
This also works: https://psalm.dev/r/789f4fa5e6 |
I found these snippets: https://psalm.dev/r/789f4fa5e6<?php
class Assert {
/**
* @psalm-assert non-empty-list $array
*
* @param mixed $array
* @param string $message
*
* @throws InvalidArgumentException
*/
public static function isNonEmptyList($array, $message = ''): void
{
}
}
/**
* @psalm-param non-empty-list<string> $values
*/
function consume(array $values): void
{
Assert::isNonEmptyList($values);
}
|
@greg0ire yes, but what if |
I found these snippets: https://psalm.dev/r/7b3899ba70<?php
class Assert {
/**
* @psalm-assert non-empty-list $array
*
* @param mixed $array
* @param string $message
*
* @throws InvalidArgumentException
*/
public static function isNonEmptyList($array, $message = ''): void
{
}
}
/**
* @psalm-param non-empty-list<string> $values
*/
function consume(array $values): void
{
Assert::isNonEmptyList($values);
}
consume([]);
|
Then you get a rightful error message… if you assert the list is not empty inside |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue seems quite related with #2636
With the latest version of Psalm (3.12.2) the examples given in #2636 are working fine, but if I want to give stricter type to the the entry argument, for example
list<string>
I receive an error report:ERROR: TypeDoesNotContainType - 20:13 - Cannot resolve types for $values - list<string> does not contain non-empty-list<mixed>
But not if I pass
list<mixed>
(same forarray
).Example: https://psalm.dev/r/9d7436fe23
The text was updated successfully, but these errors were encountered: