psalm
psalm copied to clipboard
Type with templated closure is not inferred correctly
Turns out I actually fixed this bug in my immutable refactoring, couldn't initially figure out why was upstream returning this weird result :) https://psalm.dev/r/a2a2c35578
I found these snippets:
https://psalm.dev/r/a2a2c35578
<?php
/**
* @template TCallback as Closure():string
*/
class A {
/** @var TCallback */
private $callback;
/** @param TCallback $callback */
public function __construct(Closure $callback) {
$this->callback = $callback;
}
/** @param TCallback $callback */
public function setCallback(Closure $callback): void {
$this->callback = $callback;
}
}
$a = new A(function() { return "a";});
/** @psalm-trace $a */;
Psalm output (using commit f6fb715):
INFO: Trace - 20:43 - $a: A<>
INFO: UnusedVariable - 19:21 - $a is never referenced or the value is not used