Skip to content

Commit

Permalink
Merge pull request #9953 from boesing/bugfix/issue-9917
Browse files Browse the repository at this point in the history
`non-empty-list` assertion for iterable
  • Loading branch information
orklah committed Jun 23, 2023
2 parents 01e2ac7 + f482a5c commit 81946bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 81946bb

Please sign in to comment.