Skip to content
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

Issue with template of template and covariance/contravariance #7103

Closed
ondrejmirtes opened this issue Apr 24, 2022 Discussed in #7102 · 3 comments · Fixed by phpstan/phpstan-src#1709
Closed

Issue with template of template and covariance/contravariance #7103

ondrejmirtes opened this issue Apr 24, 2022 Discussed in #7102 · 3 comments · Fixed by phpstan/phpstan-src#1709
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Member

Discussed in #7102

Originally posted by VincentLanglet April 24, 2022
Hi @ondrejmirtes, I have trouble to understand why I get an error from the following snippet
https://phpstan.org/r/2adcc3bb-8d05-4d79-91e1-78e282855229
Psalm doesn't report an error https://psalm.dev/r/ae8f5c32ff

I'd like to define a method with a template that I can scope by the class template.
This way
Manager<Foo|Bar>::find(Baz) is invalid.
Manager<Foo|Bar>::find(Foo) will return Foo (and not Foo|Baz).

Is it a bug ?

@ondrejmirtes ondrejmirtes added this to the Generics milestone Apr 24, 2022
@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-29: Parameter #1 $class (class-string<R of T of Entity>) of method MyManager::find() should be contravariant with parameter $class (class-string<T of object>) of method Manager<T of Entity>::find()
-29: Return type (R of T of Entity) of method MyManager::find() should be covariant with return type (T of object) of method Manager<T of Entity>::find()
+No errors

@ondrejmirtes
Copy link
Member Author

/cc @rvanvelzen Regression test please 😊

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants