Skip to content

Commit 26b0eb7

Browse files
committed
Test pipe operator with generics
1 parent 14ad549 commit 26b0eb7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/PHPStan/Analyser/nsrt/pipe-operator.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PipeOperatorTypes;
44

5+
use stdClass;
56
use function PHPStan\Testing\assertType;
67

78
class Foo
@@ -223,4 +224,26 @@ public function testConditional(): void
223224
assertType('int', 'foo' |> fn($x) => $this->doConditional($x));
224225
}
225226

227+
/**
228+
* @template T
229+
* @param T $input
230+
* @return T
231+
*/
232+
public function doGenerics($input)
233+
{
234+
return $t;
235+
}
236+
237+
public function testGenerics(): void
238+
{
239+
assertType(stdClass::class, new stdClass() |> $this->doGenerics(...));
240+
assertType(stdClass::class, new stdClass() |> $this->doGenerics(...));
241+
242+
assertType(stdClass::class, new stdClass() |> fn($x) => $this->doGenerics($x));
243+
assertType(stdClass::class, new stdClass() |> fn($x) => $this->doGenerics($x));
244+
245+
assertType('null', null |> $this->doConditional(...) |> $this->doGenerics(...));
246+
assertType('int', 'foo' |> $this->doConditional(...) |> $this->doGenerics(...));
247+
}
248+
226249
}

0 commit comments

Comments
 (0)