Skip to content

Commit 14ad549

Browse files
committed
Test pipe operator with conditional types
1 parent 3338e26 commit 14ad549

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,25 @@ public function doArrayFilter(array $ints): void
202202
})(1));
203203
}
204204

205+
/**
206+
* @return ($s is null ? null : int)
207+
*/
208+
public function doConditional(string|null $s): int|null
209+
{
210+
if ($s === null) {
211+
return null;
212+
}
213+
214+
return strlen($s);
215+
}
216+
217+
public function testConditional(): void
218+
{
219+
assertType('null', null |> $this->doConditional(...));
220+
assertType('int', 'foo' |> $this->doConditional(...));
221+
222+
assertType('null', null |> fn($x) => $this->doConditional($x));
223+
assertType('int', 'foo' |> fn($x) => $this->doConditional($x));
224+
}
225+
205226
}

0 commit comments

Comments
 (0)