psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Type with templated closure is not inferred correctly

Open danog opened this issue 2 years ago • 1 comments

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

danog avatar Jul 22 '22 11:07 danog

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

psalm-github-bot[bot] avatar Jul 22 '22 11:07 psalm-github-bot[bot]