Optional callable parameters are not enforced
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).
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!
Sort of related to #8300, they could probably be fixed at the same time.