psalm
psalm copied to clipboard
Conditional types comparison works in a wrong way in assertions
https://psalm.dev/r/52685a5fda
For some reason string|int is string
makes true.
I found these snippets:
https://psalm.dev/r/52685a5fda
<?php
/**
* @template T
* @param T $foo
* @psalm-assert-if-true (T is string ? numeric-string : int) $foo
*/
function foo(string|int $foo): bool
{
return true;
}
function bar(string|int $bar): void
{
if (foo($bar)) {
/** @psalm-trace $bar */; # it should be numeric-string|int here
}
}
Psalm output (using commit afe85fa):
INFO: Trace - 16:33 - $bar: numeric-string
https://psalm.dev/r/9528b9da34
int|string is int|string
makes false.
I found these snippets:
https://psalm.dev/r/9528b9da34
<?php
/**
* @template T
* @param T $foo
* @psalm-assert-if-true (T is int|string ? numeric-string|int : (T is string ? numeric-string : int)) $foo
*/
function foo(int|string $foo): bool
{
return true;
}
function bar(int|string $bar): void
{
if (foo($bar)) {
/** @psalm-trace $bar */;
}
}
Psalm output (using commit afe85fa):
INFO: Trace - 16:33 - $bar: numeric-string