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

Cloning $this doesn't preserve generic bound for static type #4729

Closed
hrach opened this issue Mar 19, 2021 · 4 comments
Closed

Cloning $this doesn't preserve generic bound for static type #4729

hrach opened this issue Mar 19, 2021 · 4 comments

Comments

@hrach
Copy link
Contributor

hrach commented Mar 19, 2021

Bug report

With the latest parent/static rewrite I'm getting Method A::get() should return static(A) but returns A<mixed>..

/** @template T of int */
interface I { 
	/**
	 * @return static
	 */
	function get(): I;
}
/**
 * @template T of int
 * @implements I<T>
 */
final class B implements I { function get(): I { return clone $this; } }

Code snippet that reproduces the problem

https://phpstan.org/r/fbb73145-4bf3-4129-92d2-c4a6537f03d5

Expected output

no error

@ondrejmirtes
Copy link
Member

Hi, the error isn't about the clone keyword, but about the method signature:

Return type (B) of method B::get() should be compatible with return type (static(I)) of method I::get()

And it only happens when the class is final: https://phpstan.org/r/7ccf0ea9-1f2a-461a-b0b4-632587b78543

I'm gonna investigate this.

@hrach
Copy link
Contributor Author

hrach commented Mar 20, 2021

I'm sorry I knew it is only with final case but forgot to write it.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@8f0150d

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants