Skip to content

Commit 8bc6aab

Browse files
phpstan-botstaabm
authored andcommitted
Add regression test for #13759
Closes phpstan/phpstan#13759
1 parent 1fcb7d2 commit 8bc6aab

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1); // lint >= 8.0
2+
3+
namespace Bug13759;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Test
8+
{
9+
public function scenario(): void
10+
{
11+
$ints = [];
12+
foreach (['a', 'b'] as $key) {
13+
$ints[$key] = 1;
14+
}
15+
$ints['c'] = 1;
16+
17+
assertType("array{a?: 1, b?: 1, c: 1}", $ints);
18+
19+
foreach (['a'] as $key) {
20+
$ints[$key] = $this->intToSomething($ints[$key]);
21+
}
22+
23+
assertType("array{a: float|string, b?: 1, c: 1}", $ints);
24+
}
25+
26+
/**
27+
* @return string|float
28+
*/
29+
protected function intToSomething(int $int): string|float {
30+
return mt_rand(1, 2) ? (string)$int : (float)$int;
31+
}
32+
}

0 commit comments

Comments
 (0)