Skip to content

Commit 4e894ee

Browse files
phpstan-botclaude
andcommitted
Add test for phpstan/phpstan#10938: check if Iterator is empty via never
Adds nsrt and rule test coverage for the related issue where checking if a collection is empty using (TValue is never ? true : bool) conditional return type was not working. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent db3018b commit 4e894ee

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10938;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template TKey
9+
* @template TValue
10+
* @extends \IteratorAggregate<TKey, TValue>
11+
*/
12+
interface Collection extends \IteratorAggregate
13+
{
14+
/**
15+
* @return (TValue is never ? true : bool)
16+
*/
17+
function isEmpty(): bool;
18+
}
19+
20+
/** @param Collection<never, never> $c */
21+
function emptyCollection(Collection $c): void {
22+
assertType('true', $c->isEmpty());
23+
}
24+
25+
/** @param Collection<int, string> $c */
26+
function nonEmptyCollection(Collection $c): void {
27+
assertType('bool', $c->isEmpty());
28+
}

0 commit comments

Comments
 (0)