psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Optional callable parameters are not enforced

Open stof opened this issue 3 years ago • 2 comments

https://psalm.dev/r/1b710fb4db does not report any error while executing it breaks (see https://3v4l.org/vjkCN)

It should report an error on line 11, as the callback has a type callable(string): string, which cannot be passed to callable(string=): string.

For reference, the same issue exists in phpstan. It is tracked at https://github.com/phpstan/phpstan/issues/7320 (they used to fix it, but they reverted it due to the ecosystem impact because doctrine/collections used to have wrong type declarations for their callbacks, but this is now fixed in doctrine/collections 1.7.2).

stof avatar Aug 27 '22 16:08 stof

I found these snippets:

https://psalm.dev/r/1b710fb4db
<?php

/**
 * @param callable(string=):string $callable
 */
function map(callable $callable): void
{
    echo $callable();
}

map(fn(string $a): string => $a);
Psalm output (using commit afe85fa):

No issues!

psalm-github-bot[bot] avatar Aug 27 '22 16:08 psalm-github-bot[bot]

Sort of related to #8300, they could probably be fixed at the same time.

AndrolGenhald avatar Aug 27 '22 19:08 AndrolGenhald