Open Shira-3749 opened 6 months ago
I found these snippets:
Note to future me: callable(T):void
should be valid in this context, but callable():T
shouldn't.
It would be awesome if Psalm supported this Scala machinery on callables and variance: https://scastie.scala-lang.org/ZbzouFbvRHGPSwwB8OrNoA
+A
stands for @template-covariant A
-A
is @template-contravariant A
Unit
is void
A => Boolean
is callable(A): bool
(A => Boolean) => Boolean
is callable(callable(A): bool): bool
When a class defines
@template-covariant T
and one of the methods has acallable
parameter which acceptsT
as an argument, I'm getting anInvalidTemplateParam
error:https://psalm.dev/r/2eb66f01fe
I'm not sure the error is valid in this case. (And it seems to work fine otherwise.)
PHPStan doesn't seem to mind this: https://phpstan.org/r/ac9be5aa-4437-40c3-b55d-3ffaa236cb67 But will also error when it's an actual issue: https://phpstan.org/r/96d33c99-1ff7-4541-b024-c8cfaea34e30
I've also tried it in C# (as a language with native generics support) and it seems to allow this as well:
(
out
is equivalent to@template-covariant
here)