Skip to content

Commit 61dc178

Browse files
committed
regression test
1 parent c168155 commit 61dc178

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,4 +1276,9 @@ public function testBug9494(): void
12761276
$this->analyse([__DIR__ . '/data/bug-9494.php'], []);
12771277
}
12781278

1279+
public function testBug8438(): void
1280+
{
1281+
$this->analyse([__DIR__ . '/data/bug-8438.php'], []);
1282+
}
1283+
12791284
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug8438;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param array<string, string> $array
9+
*
10+
* @return array{expr: mixed, ...}
11+
*/
12+
protected function foo(array $array): array
13+
{
14+
$rnd = mt_rand();
15+
if ($rnd === 0) {
16+
return ['expr' => 'test'];
17+
} elseif ($rnd === 1) {
18+
// no error with checkBenevolentUnionTypes: false (default even with l9 + strict rules)
19+
return ['expr' => 'test', 1 => 'ok'];
20+
} else {
21+
// phpstan must understand 'expr' key is always present in the result,
22+
// then there will be no error here neither
23+
return array_merge($array, ['expr' => 'test', 1 => 'ok']);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)