New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contravariant bounds in generics #3960
Comments
@dktapps PHPStan now reports different result with your code snippet: @@ @@
-47: Parameter #2 $handlers of function callEvent expects array<EventHandler<SomeEventSubclass>>, array<EventHandler<SomeEvent>|EventHandler<SomeEventSubclass>> given.
+47: Parameter #2 $handlers of function callEvent expects array<EventHandler<SomeEvent>>, array<EventHandler<SomeEvent>|EventHandler<SomeEventSubclass>>&nonEmpty given. Full report
|
@dktapps After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@dktapps After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-47: Parameter #2 $handlers of function callEvent expects array<EventHandler<SomeEventSubclass>>, array<EventHandler<SomeEvent>|EventHandler<SomeEventSubclass>> given.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@dktapps After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-47: Parameter #2 $handlers of function callEvent expects array<EventHandler<SomeEventSubclass>>, array<EventHandler<SomeEvent>|EventHandler<SomeEventSubclass>> given.
+47: Parameter #2 $handlers of function callEvent expects array<EventHandler<SomeEvent>>, non-empty-array<EventHandler<SomeEvent>|EventHandler<SomeEventSubclass>> given. Full report
|
Here's how to implement it: #7502 (comment) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature request
I have an event handler system where things that want to listen to an event can subscribe to it, by class.
This system also allows handlers to receive events which are of a subclass of the event they want to receive.
Closures already support contravariance on parameters, so I can implement this using bare closures, like this: https://phpstan.org/r/e59a6d1d-3bbd-411e-83ba-049a85782c9e
But I can't wrap the closures in objects, because generics don't support contravariant bounds: https://phpstan.org/r/d3180b26-22a2-44c0-83ce-01e757299b90
(These samples are entirely manufactured to make the point; the real system I need this for is implemented in PocketMine-MP since 2018 or so).
The text was updated successfully, but these errors were encountered: