Skip to content

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

Merged
ondrejmirtes merged 1 commit intophpstan:masterfrom
hrach:variance_in_functions
Aug 5, 2020
Merged

generics: disallow variance definition other than in class or interface#278
ondrejmirtes merged 1 commit intophpstan:masterfrom
hrach:variance_in_functions

Conversation

@hrach
Copy link
Copy Markdown
Contributor

@hrach hrach commented Jul 16, 2020

No description provided.

@hrach hrach force-pushed the variance_in_functions branch from f10eb4d to 6c976f0 Compare July 16, 2020 18:22
@hrach
Copy link
Copy Markdown
Contributor Author

hrach commented Jul 16, 2020

Build failures seems unrelated.

@hrach hrach force-pushed the variance_in_functions branch from 6c976f0 to 4e1a401 Compare July 21, 2020 06:58
@ondrejmirtes
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 hrach force-pushed the variance_in_functions branch from 4e1a401 to 760f027 Compare August 4, 2020 18:24
@hrach
Copy link
Copy Markdown
Contributor Author

hrach commented Aug 4, 2020

Done, thanks!

@ondrejmirtes ondrejmirtes merged commit f7d2d75 into phpstan:master Aug 5, 2020
@ondrejmirtes
Copy link
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

3 participants