Skip to content

Commit

Permalink
Narrow down type T of RecursiveIteratorIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 25, 2021
1 parent d29d098 commit d28b61b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stubs/iterable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ArrayIterator implements SeekableIterator, ArrayAccess, Countable
}

/**
* @template T of \Traversable
* @template T of \RecursiveIterator|\IteratorAggregate
* @mixin T
*/
class RecursiveIteratorIterator
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Classes/InstantiationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,14 @@ public function testBug1711(): void
$this->analyse([__DIR__ . '/data/bug-1711.php'], []);
}

public function testBug3425(): void
{
$this->analyse([__DIR__ . '/data/bug-3425.php'], [
[
'Parameter #1 $it of class RecursiveIteratorIterator constructor expects T of IteratorAggregate|RecursiveIterator, Generator<int, int, mixed, void> given.',
5,
],
]);
}

}
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Classes/data/bug-3425.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php declare(strict_types = 1);

namespace Bug3425;

new \RecursiveIteratorIterator((function() { yield 22; })());

0 comments on commit d28b61b

Please sign in to comment.