You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@return static<...> on a template-typed receiver collapses to the template and drops the new type arguments #13997
Base::rebuild() is declared @return static<NewK, NewV>.
On a concrete receiver Base<int, string>, rebuild('x', 1.5) is Base<'x', float(1.5)>&static, as expected.
On a receiver typed as a template C of Base<int, string>, the same call is Trace: $r: C:fn-templated as Base<int, string>. static is replaced by C and the new type arguments are dropped.
As a result, returnsTheTemplate() returns Base<'x', float> as @return C and Psalm reports nothing.
What you expected
On a template receiver, static<NewK, NewV> should keep the new type arguments, for example Base<'x', float(1.5)> (the template's bound class with the substituted arguments). Then returnsTheTemplate() reports InvalidReturnStatement. Collapsing to C is only correct when the arguments equal the receiver's own.
Psalm version, PHP version
psalm.dev dev-master@e141f40d4, PHP 8.3; also Psalm 7.7.0 and local dev-master, PHP 8.5.
Related
#13988 is the same static<...> family with a different trigger: there the arguments are applied by position to a subclass with a different template list.
Impact
psalm/psalm-plugin-laravel works around it for Laravel's Collection::groupBy() / keyBy() (@return static<...> in Laravel's docblocks): psalm/psalm-plugin-laravel#2332. Without that, a wrong @return C on a template-typed collection goes unreported.
Activity
psalm-github-bot commentedon Nov 16, 2026
I found these snippets:
https://psalm.dev/r/4deffd8a2e
docs(collections): link the template-receiver workaround to vimeo/psa…
Report wrong `@return` on template-bound `groupBy()` and `keyBy()` re…
fix(templates): static<...> on a template receiver keeps its new type…