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

Checking for instanceof subclass breaks return type when using templates #6266

Closed
AJenbo opened this issue Jan 1, 2022 · 3 comments
Closed

Comments

@AJenbo
Copy link
Contributor

AJenbo commented Jan 1, 2022

Bug report

If a function returns the given input but makes a check for a subclass it is flagged as an incompatible type.

Method MyClass::returnInput() should return T of BaseClass but returns (SubClass&T of BaseClass)|T of BaseClass.

But SubClass&T of BaseClass is compatible with T of BaseClass (T === T) and should not produce an error.

Code snippet that reproduces the problem

https://phpstan.org/r/ce00808b-84c3-46f7-96ff-b1673be83cfc

Found when analyzing https://github.com/pdepend/pdepend (PHPMD) at level 3.

@ondrejmirtes
Copy link
Member

Fixed recently, works on PHPStan 1.4.4.

@AJenbo
Copy link
Contributor Author

AJenbo commented Feb 1, 2022

Nice!

@github-actions
Copy link

github-actions bot commented Mar 5, 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 Mar 5, 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

2 participants