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

Type parameters usage at forbidden positions #10609

Open
klimick opened this issue Feb 20, 2024 · 5 comments
Open

Type parameters usage at forbidden positions #10609

klimick opened this issue Feb 20, 2024 · 5 comments

Comments

@klimick
Copy link

klimick commented Feb 20, 2024

Bug report

Phpstan allows to use type parameters where they cannot be used.

Code snippet that reproduces the problem

https://phpstan.org/r/8dc1c703-eb15-408a-a146-83c8ead2c840

Expected output

"covariant type A occurs in contravariant position"

Did PHPStan help you today? Did it make you happy in any way?

No response

@klimick
Copy link
Author

klimick commented Feb 20, 2024

Why it is bad at runtime: https://3v4l.org/A0joX

@klimick
Copy link
Author

klimick commented Feb 20, 2024

More complex example: https://phpstan.org/r/476e20b9-112d-49c4-a3a1-f86342e3598a
And full runtime example: https://3v4l.org/U1rIf

@ondrejmirtes
Copy link
Member

/cc @jiripudil

@jiripudil
Copy link
Contributor

Hm, looks like ClosureType uses NonGenericTypeTrait, and thus does not report referenced template types at all. Perhaps it should implement inferTemplateTypes and getReferencedTemplateTypes the same way that CallableType does?

@ondrejmirtes
Copy link
Member

Closures cannot be generic, not until #8964 is implemented. But yeah, it should still implement inferTemplateTypes and getReferencedTemplateTypes because that's totally relevant even today.

@ondrejmirtes ondrejmirtes added this to the Generics milestone Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants