Skip to content

Commit c9b5c12

Browse files
committed
Regression test
1 parent 7621e11 commit c9b5c12

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10339,6 +10339,7 @@ public function dataFileAsserts(): iterable
1033910339
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4700.php');
1034010340
yield from $this->gatherAssertTypes(__DIR__ . '/data/phpdoc-in-closure-bind.php');
1034110341
yield from $this->gatherAssertTypes(__DIR__ . '/data/multi-assign.php');
10342+
yield from $this->gatherAssertTypes(__DIR__ . '/data/generics-reduce-types-first.php');
1034210343
}
1034310344

1034410345
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
// inspired by: https://github.com/microsoft/TypeScript/pull/5738
4+
5+
namespace GenericsReduceTypesFirst;
6+
7+
use function PHPStan\Analyser\assertType;
8+
9+
class Foo
10+
{
11+
12+
/**
13+
* @template T
14+
* @param T|string $p
15+
* @return T
16+
*/
17+
public function doFoo($p)
18+
{
19+
20+
}
21+
22+
/**
23+
* @param string[]|string $a
24+
* @param string|string[] $b
25+
* @param string[] $c
26+
*/
27+
public function doBar($a, $b, $c, string $d)
28+
{
29+
assertType('array<string>', $this->doFoo($a));
30+
assertType('array<string>', $this->doFoo($b));
31+
assertType('array<string>', $this->doFoo($c));
32+
assertType('string', $this->doFoo($d));
33+
}
34+
35+
}

0 commit comments

Comments
 (0)