Skip to content

Commit a439851

Browse files
Fix non regression test
1 parent 10c3ec4 commit a439851

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

tests/PHPStan/Analyser/nsrt/bug-10085.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@
66

77
use function PHPStan\Testing\assertType;
88

9-
/**
10-
* @param list<string> $a
11-
* @param list<string> $b
12-
*/
13-
function foo(array $a, array $b): void {
14-
$foo = [...$a, ...$b];
15-
assertType('list<string>', $foo);
9+
class HelloWorld
10+
{
11+
/**
12+
* @param array<int, string> $foo
13+
* @param list<string> $bar
14+
*/
15+
public function sayHello(array $foo, array $bar): void
16+
{
17+
$a = $foo;
18+
if ($a === []) {
19+
$a = $bar;
20+
}
21+
22+
if ($a === []) {
23+
return;
24+
}
25+
26+
assertType('array<int, string>', $foo);
27+
}
1628
}

tests/PHPStan/Analyser/nsrt/bug-14211.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
use function PHPStan\Testing\assertType;
88

9-
/**
10-
* @param array<string, int> $array
11-
*/
12-
function foo(string $key, array $array): void {
13-
if (array_key_exists($key, $array)) {
14-
$value = $array[$key];
15-
assertType('int', $value);
16-
} else {
17-
$value = null;
18-
}
9+
/** @param array<mixed> $data */
10+
function DoSomithing(array $data): bool {
11+
12+
if (!isset($data['x']))
13+
return false;
1914

20-
assertType('int|null', $value);
15+
$m = isset($data['y']);
2116

22-
if ($value !== null) {
23-
assertType('bool', array_key_exists($key, $array)); // should be true, see phpstan/phpstan#14211
17+
if ($m) {
18+
assertType('true', $m); // ok: true
2419
}
20+
assertType('bool', $m); // ok: bool
21+
22+
if ($m) {
23+
assertType('true', $m); // <-- should not be: NEVER
24+
}
25+
26+
return true;
2527
}

0 commit comments

Comments
 (0)