File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -159,3 +159,32 @@ class RecursiveIteratorIterator
159
159
}
160
160
161
161
}
162
+
163
+ /**
164
+ * @template-covariant TKey
165
+ * @template-covariant TValue
166
+ *
167
+ * @template-extends Iterator<TKey, TValue>
168
+ */
169
+ interface OuterIterator extends Iterator {
170
+ /**
171
+ * @return Iterator<TKey, TValue>
172
+ */
173
+ public function getInnerIterator();
174
+ }
175
+
176
+ /**
177
+ * @template-covariant TKey
178
+ * @template-covariant TValue
179
+ * @template TIterator as Traversable<TKey, TValue>
180
+ *
181
+ * @template-implements OuterIterator<TKey, TValue>
182
+ *
183
+ * @mixin TIterator
184
+ */
185
+ class IteratorIterator implements OuterIterator {
186
+ /**
187
+ * @param TIterator $iterator
188
+ */
189
+ public function __construct(Traversable $iterator) {}
190
+ }
Original file line number Diff line number Diff line change @@ -10956,6 +10956,11 @@ public function dataNestedGenericIncompleteConstructor(): array
10956
10956
return $ this ->gatherAssertTypes (__DIR__ . '/data/nested-generic-incomplete-constructor.php ' );
10957
10957
}
10958
10958
10959
+ public function dataIteratorIterator (): array
10960
+ {
10961
+ return $ this ->gatherAssertTypes (__DIR__ . '/data/iterator-iterator.php ' );
10962
+ }
10963
+
10959
10964
/**
10960
10965
* @param string $file
10961
10966
* @return array<string, mixed[]>
@@ -11208,6 +11213,7 @@ private function gatherAssertTypes(string $file): array
11208
11213
* @dataProvider dataBug3922
11209
11214
* @dataProvider dataNestedGenericTypesUnwrapping
11210
11215
* @dataProvider dataNestedGenericIncompleteConstructor
11216
+ * @dataProvider dataIteratorIterator
11211
11217
* @param string $assertType
11212
11218
* @param string $file
11213
11219
* @param mixed ...$args
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace IteratorIteratorTest ;
4
+
5
+ use function PHPStan \Analyser \assertType ;
6
+
7
+ class Foo
8
+ {
9
+
10
+ /**
11
+ * @param \ArrayIterator<int, string> $it
12
+ */
13
+ public function doFoo (\ArrayIterator $ it ): void
14
+ {
15
+ $ iteratorIterator = new \IteratorIterator ($ it );
16
+ assertType ('Iterator<int, string> ' , $ iteratorIterator ->getInnerIterator ());
17
+ assertType ('array<int, string> ' , $ iteratorIterator ->getArrayCopy ());
18
+ }
19
+
20
+ }
You can’t perform that action at this time.
0 commit comments