Skip to content

Commit 2abdcdb

Browse files
committed
Add regression test for array_reduce bucket accumulator
Amp-Thread-ID: https://ampcode.com/threads/T-01a21c3c-cedc-7330-a083-cc986590888f
1 parent 2b60ab0 commit 2abdcdb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7280;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
$result = array_reduce(
8+
['test1', 'test2'],
9+
static function (array $carry, string $value): array{
10+
assertType("array{starts: array{}, ends: array{}}|array{starts: non-empty-list<'test1'|'test2'>, ends: non-empty-list<'test1'|'test2'>}", $carry);
11+
$carry['starts'][] = $value;
12+
$carry['ends'][] = $value;
13+
14+
return $carry;
15+
},
16+
initial: ['starts' => [], 'ends' => []],
17+
);
18+
assertType("array{starts: non-empty-list<'test1'|'test2'>, ends: non-empty-list<'test1'|'test2'>}", $result);

0 commit comments

Comments
 (0)