psalm
psalm copied to clipboard
Psalm don't keep callable type in union types after condition
See https://psalm.dev/r/393eb25a8a
I found these snippets:
https://psalm.dev/r/393eb25a8a
<?php
/**
* @psalm-param array|callable():array $var
*/
function text(mixed $var): array
{
if (is_array($var)) {
return $var;
}
/** @psalm-trace $var */
return call_user_func($var);
}
Psalm output (using commit 16b24bd):
INFO: MixedReturnStatement - 14:12 - Could not infer a return type
INFO: Trace - 14:5 - $var: callable-object|callable-string
~Same behavior with Closure: https://psalm.dev/r/0f016891bd~
I found these snippets:
https://psalm.dev/r/0f016891bd
<?php
/**
* @psalm-param array|Clsoure():array $var
*/
function text(mixed $var): array
{
if (is_array($var)) {
return $var;
}
/** @psalm-trace $var */
return $var();
}
Psalm output (using commit be92afa):
ERROR: InvalidDocblock - 4:17 - Parenthesis must be preceded by “Closure”, “callable”, "pure-callable" or a valid @method name in docblock for text
INFO: MixedFunctionCall - 14:12 - Cannot call function on mixed
INFO: MixedReturnStatement - 14:12 - Could not infer a return type
INFO: Trace - 14:5 - $var: mixed
Are you sure it's not due to the typo in Closure in your docblock?
Yes. Sorry, I'm wrong.