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

generics: disallow variance definition other than in class or interface #278

Merged
merged 1 commit into from Aug 5, 2020

Conversation

hrach
Copy link
Contributor

@hrach hrach commented Jul 16, 2020

No description provided.

@hrach
Copy link
Contributor Author

hrach commented Jul 16, 2020

Build failures seems unrelated.

@ondrejmirtes
Copy link
Member

I'd like to hear @muglug's opinion whether it makes sense to allow and read @template-covariant above functions and methods.

My opinion is that it's not entirely wrong to use that, in a world where you're able to materialize function foo<T of Foo> as a type - invariant version would only accept foo<Foo>, covariant version would also accept foo<Bar> where Bar extends Foo.

@hrach
Copy link
Contributor Author

hrach commented Jul 27, 2020

Yes, I will have to give it a thought. I wanted to disable it here as there is no point having declaration site variance for functions but it is actually use-site variance with the same syntax :D

@muglug
Copy link
Contributor

muglug commented Jul 27, 2020

@template-covariant doesn't really make sense to me for methods – does it exist in other languages?

@hrach
Copy link
Contributor Author

hrach commented Jul 29, 2020

Ok, seems its not supported anywhere, I researched some langs and added this info explicitly into table: https://hrach.dev/posts/variance-elsewhere/

@ondrejmirtes
Copy link
Member

Please fix the build and I'll merge it (PHP 8 tests are now expected to fail.)

It's enough to run GenericsIntegrationTest locally and commit the updated JSON files.

@hrach
Copy link
Contributor Author

hrach commented Aug 4, 2020

Done, thanks!

@ondrejmirtes ondrejmirtes merged commit f7d2d75 into phpstan:master Aug 5, 2020
1 check passed
@ondrejmirtes
Copy link
Member

Thank you!

@hrach hrach deleted the variance_in_functions branch August 5, 2020 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants