Skip to content

Commit 6f58959

Browse files
phpstan-botclaude
andcommitted
Add test for list<string> key type preserved through ArrayIterator
Adds a test case from phpstan.org/r/c448c867 verifying that when a list<string> is passed to new ArrayIterator(), the inferred key type is int<0, max> (not generalized to int). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f88e210 commit 6f58959

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/PHPStan/Analyser/nsrt/bug-12601.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ public function getIterator(): Traversable
2424
}
2525
}
2626

27+
class HelloWorld3
28+
{
29+
/** @var ArrayIterator<int, string> */
30+
private ArrayIterator $a;
31+
32+
/** @param list<string> $map */
33+
public function __construct(private array $map) {
34+
$a = new ArrayIterator($this->map);
35+
assertType('ArrayIterator<int<0, max>, string>', $a);
36+
37+
$this->a = $a;
38+
}
39+
}
40+
2741
/** @implements IteratorAggregate<int<0, max>, non-empty-string> */
2842
class HelloWorld2 implements IteratorAggregate
2943
{

0 commit comments

Comments
 (0)