|
4 | 4 |
|
5 | 5 | use function PHPStan\Testing\assertType; |
6 | 6 |
|
| 7 | +/** |
| 8 | + * @param array<int> $items |
| 9 | + */ |
| 10 | +function functionProcessInts(array &$items): void |
| 11 | +{ |
| 12 | + $items = [1, 2]; |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | + * @param array<string> $items |
| 17 | + */ |
| 18 | +function functionProcessStrings(array &$items): void |
| 19 | +{ |
| 20 | + $items = ['a', 'b']; |
| 21 | +} |
| 22 | + |
7 | 23 | class HelloWorld |
8 | 24 | { |
9 | 25 | /** |
@@ -53,41 +69,48 @@ protected function testParamOut(): void |
53 | 69 | } |
54 | 70 |
|
55 | 71 | /** |
56 | | - * @param array<mixed> $items |
57 | | - * @param-out list<string> $items |
| 72 | + * @param array<int> $items |
| 73 | + */ |
| 74 | + protected function processInts(array &$items): void |
| 75 | + { |
| 76 | + $items = [1, 2]; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @param array<string> $items |
58 | 81 | */ |
59 | | - protected function processWithParamOutStrings(array &$items): void |
| 82 | + protected function processStrings(array &$items): void |
60 | 83 | { |
61 | 84 | $items = ['a', 'b']; |
62 | 85 | } |
63 | 86 |
|
64 | 87 | /** |
65 | | - * @param 'processWithParamOut'|'processWithParamOutStrings' $method |
| 88 | + * @param 'Bug6799\functionProcessInts'|'Bug6799\functionProcessStrings' $function |
66 | 89 | */ |
67 | | - protected function testUnionStringCallbacks(string $method): void |
| 90 | + protected function testUnionStringCallbacks(string $function): void |
68 | 91 | { |
69 | 92 | $items = []; |
70 | | - call_user_func_array([$this, $method], [&$items]); |
71 | | - assertType('list<int|string>', $items); |
| 93 | + call_user_func_array($function, [&$items]); |
| 94 | + assertType('mixed', $items); // Could be array<int>|array<string> |
72 | 95 | } |
73 | 96 |
|
74 | 97 | /** |
75 | | - * @param array{$this, 'processWithParamOut'}|array{$this, 'processWithParamOutStrings'} $callback |
| 98 | + * @param array{$this, 'processInts'}|array{$this, 'processStrings'} $callback |
76 | 99 | */ |
77 | 100 | protected function testUnionArrayCallbacks(array $callback): void |
78 | 101 | { |
79 | 102 | $items = []; |
80 | 103 | call_user_func_array($callback, [&$items]); |
81 | | - assertType('list<int|string>', $items); |
| 104 | + assertType('mixed', $items); // Could be array<int>|array<string> |
82 | 105 | } |
83 | 106 |
|
84 | 107 | /** |
85 | | - * @param 'processWithParamOut'|array{$this, 'processWithParamOutStrings'} $callback |
| 108 | + * @param 'Bug6799\functionProcessInts'|array{$this, 'processStrings'} $callback |
86 | 109 | */ |
87 | 110 | protected function testMixedUnionCallback($callback): void |
88 | 111 | { |
89 | 112 | $items = []; |
90 | 113 | call_user_func_array($callback, [&$items]); |
91 | | - assertType('array{}', $items); |
| 114 | + assertType('mixed', $items); // Could be array<int>|array<string> |
92 | 115 | } |
93 | 116 | } |
0 commit comments