Skip to content

Commit

Permalink
Fix native return type of array_chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 25, 2023
1 parent 7cb4901 commit e4a6d20
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
'AppendIterator::rewind' => ['void'],
'AppendIterator::valid' => ['bool'],
'array_change_key_case' => ['array', 'input'=>'array', 'case='=>'int'],
'array_chunk' => ['list<array[]>', 'input'=>'array', 'size'=>'positive-int', 'preserve_keys='=>'bool'],
'array_chunk' => ['list<array>', 'input'=>'array', 'size'=>'positive-int', 'preserve_keys='=>'bool'],
'array_column' => ['array', 'array'=>'array', 'column_key'=>'mixed', 'index_key='=>'mixed'],
'array_combine' => ['array|false', 'keys'=>'array', 'values'=>'array'],
'array_count_values' => ['array<positive-int>', 'input'=>'array'],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7607.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/ibm_db2.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/benevolent-union-math.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8956.php');
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8956.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Bug8956;

use function PHPStan\Testing\assertNativeType;
use function PHPStan\Testing\assertType;

class Foo
{

public function doFoo(): void
{
foreach (array_chunk(range(0, 10), 60) as $chunk) {
assertType('array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}', $chunk);
assertNativeType('array', $chunk);
foreach ($chunk as $val) {
assertType('0|1|2|3|4|5|6|7|8|9|10', $val);
assertNativeType('mixed', $val);
}
}
}

public function doBar(): void
{
assertType('array{array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}', array_chunk(range(0, 10), 60));
assertNativeType('list<array>', array_chunk(range(0, 10), 60));
}

}

0 comments on commit e4a6d20

Please sign in to comment.