From 0e725d8bd8aa75375c5c4bfd84a97cd0a5cc854e Mon Sep 17 00:00:00 2001 From: alleknalle Date: Thu, 26 Feb 2026 11:33:36 +0100 Subject: [PATCH] fix list methods so psalm doesn't see it as list --- src/Assert.php | 12 +++----- src/Mixin.php | 30 ++++++++----------- .../static-analysis/assert-isNonEmptyList.php | 12 ++++++++ 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 24f9c1ac..6b9825e7 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1986,11 +1986,9 @@ public static function countBetween(mixed $array, mixed $min, mixed $max, string /** * @psalm-pure * - * @psalm-assert list $array + * @psalm-assert list $array * - * @psalm-return list - * - * @template T + * @psalm-return list * * @throws InvalidArgumentException */ @@ -2008,11 +2006,9 @@ public static function isList(mixed $array, string $message = ''): array /** * @psalm-pure * - * @psalm-assert non-empty-list $array + * @psalm-assert non-empty-list $array * - * @psalm-return non-empty-list - * - * @template T + * @psalm-return non-empty-list * * @throws InvalidArgumentException */ diff --git a/src/Mixin.php b/src/Mixin.php index 17ce9532..0b42c5ae 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4754,10 +4754,9 @@ public static function allNullOrCountBetween(mixed $array, mixed $min, mixed $ma /** * @psalm-pure * - * @psalm-assert list|null $array + * @psalm-assert list|null $array * - * @template T - * @return list|null + * @return list|null * * @throws InvalidArgumentException */ @@ -4771,10 +4770,9 @@ public static function nullOrIsList(mixed $array, string $message = ''): mixed /** * @psalm-pure * - * @psalm-assert iterable> $array + * @psalm-assert iterable> $array * - * @template T - * @return iterable> + * @return iterable> * * @throws InvalidArgumentException */ @@ -4792,10 +4790,9 @@ public static function allIsList(mixed $array, string $message = ''): mixed /** * @psalm-pure * - * @psalm-assert iterable|null> $array + * @psalm-assert iterable|null> $array * - * @template T - * @return iterable|null> + * @return iterable|null> * * @throws InvalidArgumentException */ @@ -4813,10 +4810,9 @@ public static function allNullOrIsList(mixed $array, string $message = ''): mixe /** * @psalm-pure * - * @psalm-assert non-empty-list|null $array + * @psalm-assert non-empty-list|null $array * - * @template T - * @return non-empty-list|null + * @return non-empty-list|null * * @throws InvalidArgumentException */ @@ -4830,10 +4826,9 @@ public static function nullOrIsNonEmptyList(mixed $array, string $message = ''): /** * @psalm-pure * - * @psalm-assert iterable> $array + * @psalm-assert iterable> $array * - * @template T - * @return iterable> + * @return iterable> * * @throws InvalidArgumentException */ @@ -4851,10 +4846,9 @@ public static function allIsNonEmptyList(mixed $array, string $message = ''): mi /** * @psalm-pure * - * @psalm-assert iterable|null> $array + * @psalm-assert iterable|null> $array * - * @template T - * @return iterable|null> + * @return iterable|null> * * @throws InvalidArgumentException */ diff --git a/tests/static-analysis/assert-isNonEmptyList.php b/tests/static-analysis/assert-isNonEmptyList.php index 027e0c12..61325674 100644 --- a/tests/static-analysis/assert-isNonEmptyList.php +++ b/tests/static-analysis/assert-isNonEmptyList.php @@ -20,6 +20,18 @@ function isNonEmptyList(mixed $value): array return $value; } +/** + * @psalm-pure + */ +function isNonEmptyListWithRange(): mixed +{ + $value = range(1, 100); + + Assert::isNonEmptyList($value); + + return $value[0]; +} + /** * @psalm-pure *