Skip to content

Commit f40c14a

Browse files
committed
Added regression test
1 parent fe873d6 commit f40c14a

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,12 @@ public function testBug9401(): void
370370
]);
371371
}
372372

373+
public function testBug7076(): void
374+
{
375+
$this->checkExplicitMixed = true;
376+
$this->checkNullables = true;
377+
378+
$this->analyse([__DIR__ . '/data/bug-7076.php'], []);
379+
}
380+
373381
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug7076;
4+
5+
/**
6+
* @param array<string, mixed> $param
7+
* @return array<string, mixed>
8+
*/
9+
function expectsStringKey(array $param): array
10+
{
11+
return $param;
12+
}
13+
14+
/**
15+
* @param array<int|string, mixed> $arguments
16+
* @return array<string, mixed>
17+
*/
18+
function foo(array $arguments): array
19+
{
20+
foreach ($arguments as $key => $argument) {
21+
if (!is_string($key)) {
22+
throw new \Exception('Key must be a string');
23+
}
24+
}
25+
26+
return $arguments;
27+
}
28+
29+
/**
30+
* @return array<string, mixed>
31+
*/
32+
function bar(mixed ...$arguments): array
33+
{
34+
foreach ($arguments as $key => $argument) {
35+
if (!is_string($key)) {
36+
throw new \Exception('Key must be a string');
37+
}
38+
39+
if (is_int($key)) {
40+
echo 'int';
41+
}
42+
}
43+
44+
return $arguments;
45+
}
46+
47+
/**
48+
* @return array<string, mixed>
49+
*/
50+
function baz(mixed ...$arguments): array
51+
{
52+
foreach ($arguments as $key => $argument) {
53+
if (is_string($key)) {
54+
continue;
55+
}
56+
57+
throw new \Exception('Key must be a string');
58+
}
59+
60+
return $arguments;
61+
}
62+
63+

0 commit comments

Comments
 (0)