Skip to content

Commit 0fa020e

Browse files
authored
Added regression test (#5585)
1 parent d34f7cc commit 0fa020e

2 files changed

Lines changed: 29 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
2+
3+
namespace Bug9004;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
$test = [];
8+
foreach (['a', 'b', 'c'] as $letter) {
9+
if (rand(0, 1) == 0) {
10+
assertType("array{}|array{hi: 'hello'}|array{hi: array{0: 42, 1?: 42}}", $test);
11+
if (isset($test['hi']) && is_string($test['hi'])) {
12+
continue;
13+
}
14+
$test['hi'][] = 42;
15+
} else {
16+
$test['hi'] = 'hello';
17+
}
18+
}

tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,15 @@ public function testAppendToArrayWithPhpIntMaxKey(): void
222222
]);
223223
}
224224

225+
public function testBug9004(): void
226+
{
227+
$this->checkUnionTypes = true;
228+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-9004.php'], [
229+
[
230+
'Cannot assign new offset to list<int>|string.',
231+
14,
232+
],
233+
]);
234+
}
235+
225236
}

0 commit comments

Comments
 (0)