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

Generic Attributes does not guess the type of a class-string #7171

Closed
BrandonlinU opened this issue May 3, 2022 · 7 comments
Closed

Generic Attributes does not guess the type of a class-string #7171

BrandonlinU opened this issue May 3, 2022 · 7 comments

Comments

@BrandonlinU
Copy link

BrandonlinU commented May 3, 2022

Bug report

I update the Doctrine Library to the newest version (2.12.2 at the moment of writing) that incorporates psalm generics for the Entity attribute, but this cause that PHPStan report many errors relative with the parameter "repositoryClass", saying that my repositories (that extends the ServiceEntityRepository) was not allowed because it not represents a class-string for EntityRepository. Because ServiceEntityRepository extends from EntityRepository, it should be covariant.
It seems that the error is unique for the generic attributes, because I testes with generic classes and PHPStan is happy with the same type constraints.

Code snippet that reproduces the problem

https://phpstan.org/r/15c3b24f-ad7c-47b0-a1d2-da219cdd5edb

Expected output

It should not throw error

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

I am not good with the words, but PHPStan help me catch many errors and save me tens of hours of painfull debugging. Keep going with that fantastic work!

@rs-ubaldi
Copy link

Same problem here today

@adrienlucas
Copy link

Seems like the same issue was encountered using psalm : doctrine/orm#9681

A fix of the doctrine/orm package is to be released (see doctrine/orm#9708) but as far as I tested, it does not solve phpstan usage.

@damosse31
Copy link

my temporary workaround in phpstan.neon to ignore this error

parameters:
	level: 8
	ignoreErrors:
		- '#repositoryClass(.*)expects class-string(.*)EntityRepository#'

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@361e064

@ondrejmirtes
Copy link
Member

Fix released in PHPStan 1.6.8: https://github.com/phpstan/phpstan/releases/tag/1.6.8

@bytehead
Copy link

Thank you 🙏

@github-actions
Copy link

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 Jun 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants