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

non-empty-list assertion for iterable #9953

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,9 @@ private static function reconcileList(

$redundant = false;
} elseif ($type instanceof TIterable) {
$array_types[] = Type::getListAtomic($type->type_params[1]);
$array_types[] = $is_non_empty
? Type::getNonEmptyListAtomic($type->type_params[1])
: Type::getListAtomic($type->type_params[1]);

$redundant = false;
} else {
Expand Down
20 changes: 20 additions & 0 deletions tests/AssertAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,26 @@ function takesAnArrayB($arg) {}
takesAnArrayB($foo);
}',
],
'iterableToNonEmptyList' => [
'code' => '<?php
final class WhateverAssert
{
/**
* @param mixed $value
* @psalm-assert non-empty-list $value
*/
public static function doAssert($value): void
{}
}

/** @var iterable<mixed,string> $iterable */
$iterable = [];

WhateverAssert::doAssert($iterable);',
'assertions' => [
'$iterable===' => 'non-empty-list<string>',
],
],
];
}

Expand Down