Skip to content

Commit e4a6d20

Browse files
committed
Fix native return type of array_chunk
1 parent 7cb4901 commit e4a6d20

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Diff for: resources/functionMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
'AppendIterator::rewind' => ['void'],
260260
'AppendIterator::valid' => ['bool'],
261261
'array_change_key_case' => ['array', 'input'=>'array', 'case='=>'int'],
262-
'array_chunk' => ['list<array[]>', 'input'=>'array', 'size'=>'positive-int', 'preserve_keys='=>'bool'],
262+
'array_chunk' => ['list<array>', 'input'=>'array', 'size'=>'positive-int', 'preserve_keys='=>'bool'],
263263
'array_column' => ['array', 'array'=>'array', 'column_key'=>'mixed', 'index_key='=>'mixed'],
264264
'array_combine' => ['array|false', 'keys'=>'array', 'values'=>'array'],
265265
'array_count_values' => ['array<positive-int>', 'input'=>'array'],

Diff for: tests/PHPStan/Analyser/NodeScopeResolverTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ public function dataFileAsserts(): iterable
12021202
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7607.php');
12031203
yield from $this->gatherAssertTypes(__DIR__ . '/data/ibm_db2.php');
12041204
yield from $this->gatherAssertTypes(__DIR__ . '/data/benevolent-union-math.php');
1205+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8956.php');
12051206
}
12061207

12071208
/**

Diff for: tests/PHPStan/Analyser/data/bug-8956.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Bug8956;
4+
5+
use function PHPStan\Testing\assertNativeType;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
11+
public function doFoo(): void
12+
{
13+
foreach (array_chunk(range(0, 10), 60) as $chunk) {
14+
assertType('array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}', $chunk);
15+
assertNativeType('array', $chunk);
16+
foreach ($chunk as $val) {
17+
assertType('0|1|2|3|4|5|6|7|8|9|10', $val);
18+
assertNativeType('mixed', $val);
19+
}
20+
}
21+
}
22+
23+
public function doBar(): void
24+
{
25+
assertType('array{array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}', array_chunk(range(0, 10), 60));
26+
assertNativeType('list<array>', array_chunk(range(0, 10), 60));
27+
}
28+
29+
}

0 commit comments

Comments
 (0)