Skip to content

Commit cc8d35f

Browse files
ChrisBrentonondrejmirtes
authored andcommitted
Regression test
Closes phpstan/phpstan#8249
1 parent 995eff9 commit cc8d35f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ public function dataFileAsserts(): iterable
12681268
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7805.php');
12691269
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-82.php');
12701270
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4565.php');
1271+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8249.php');
12711272
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-3789.php');
12721273

12731274
if (PHP_VERSION_ID >= 80100) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Bug8249;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function foo(): mixed
8+
{
9+
return null;
10+
}
11+
12+
function () {
13+
$x = foo();
14+
15+
if (is_int($x)) {
16+
assertType('int', $x);
17+
assertType('true', is_int($x));
18+
} else {
19+
assertType('mixed~int', $x);
20+
assertType('false', is_int($x));
21+
}
22+
};
23+
24+
function () {
25+
$x = ['x' => foo()];
26+
27+
if (is_int($x['x'])) {
28+
assertType('array{x: int}', $x);
29+
assertType('int', $x['x']);
30+
assertType('true', is_int($x['x']));
31+
} else {
32+
assertType('array{x: mixed~int}', $x);
33+
assertType('mixed~int', $x['x']);
34+
assertType('false', is_int($x['x']));
35+
}
36+
};

0 commit comments

Comments
 (0)