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

Nested generic argument bound is not correctly resolved to native type #4643

Closed
hrach opened this issue Mar 2, 2021 · 4 comments
Closed
Labels
Milestone

Comments

@hrach
Copy link
Contributor

hrach commented Mar 2, 2021

Bug report

interface Entity {}

/** @template E of Entity */
interface Repository {
	/**
	 * @template F of E
	 * @param F $entity
	 * @return F
	 */
	function store(Entity $entity): Entity;
}

results in

PHPDoc tag @param for parameter $entity with type F is not subtype of native type Entity.
PHPDoc tag @return with type mixed is not subtype of native type Entity.

Code snippet that reproduces the problem

https://phpstan.org/r/4f86dceb-20e1-406d-92d4-eccd8da4c31b

Expected output

no error

@ondrejmirtes ondrejmirtes added this to the Generics milestone Mar 3, 2021
@phpstan-bot
Copy link
Contributor

@hrach After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-12: PHPDoc tag @param for parameter $entity with type F is not subtype of native type Entity.
-12: PHPDoc tag @return with type mixed is not subtype of native type Entity.
-12: Template type F of method Repository::store() is not referenced in a parameter.
+No errors

@hrach
Copy link
Contributor Author

hrach commented Mar 8, 2021

Wow, thanks for fixing it, a non trivial fix I would expect.

@ondrejmirtes
Copy link
Member

Yeah, many places still didn't think that template types can be nested like that, but at least the type system is more robust (and ready for more template type bounds!)

This was referenced Mar 9, 2021
This was referenced Mar 12, 2021
@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 Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants