-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathbug-13857.php
More file actions
67 lines (57 loc) · 1.94 KB
/
bug-13857.php
File metadata and controls
67 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types = 1);
namespace Bug13857;
use function PHPStan\Testing\assertType;
/**
* @param array<int, array{state: string}> $array
*/
function test(array $array, int $id): void {
$array[$id]['state'] = 'foo';
// only one element was set to 'foo', not all of them.
assertType("non-empty-array<int, array{state: string}>", $array);
}
/**
* @param array<int, array{state?: string}> $array
*/
function testMaybe(array $array, int $id): void {
$array[$id]['state'] = 'foo';
// only one element was set to 'foo', not all of them.
assertType("non-empty-array<int, array{state?: string}>", $array);
}
/**
* @param array<int, array{state: string|bool}> $array
*/
function testUnionValue(array $array, int $id): void {
$array[$id]['state'] = 'foo';
// only one element was set to 'foo', not all of them.
assertType("non-empty-array<int, array{state: bool|string}>", $array);
}
/**
* @param array<int, array{state: string}|array{foo: int}> $array
*/
function testUnionArray(array $array, int $id): void {
$array[$id]['state'] = 'foo';
// only one element was set to 'foo', not all of them.
assertType("non-empty-array<int, non-empty-array{foo?: int, state?: string}>", $array);
}
/**
* @param array<int, array{state: string}|array{foo: int}> $array
*/
function testUnionArrayDifferentType(array $array, int $id): void {
$array[$id]['state'] = true;
assertType("non-empty-array<int, array{state: string}|non-empty-array{foo?: int, state?: true}>", $array);
}
/**
* @param array<int, array{state: 'foo'}> $array
*/
function testConstantArray(array $array, int $id): void {
$array[$id]['state'] = 'bar';
assertType("non-empty-array<int, array{state: 'bar'}|array{state: 'foo'}>", $array);
}
/**
* @param array<int, array{state: 'foo'}> $array
*/
function testConstantArrayNonScalarAssign(array $array, int $id, bool $b): void {
$array[$id]['state'] = $b;
assertType("non-empty-array<int, array{state: 'foo'}|array{state: bool}>", $array);
}