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

PHPStan hangs with trait that returns anonymous class that uses the trait #7214

Closed
ptlis opened this issue May 10, 2022 · 5 comments · Fixed by phpstan/phpstan-src#1303
Closed

Comments

@ptlis
Copy link

ptlis commented May 10, 2022

Bug report

Please review the sample code below. This appears to be specific to anonymous classes - if you switch out the anonymous class for a 'real' class that uses the trait there is no issue (e.g. https://phpstan.org/r/2fc4cc39-6ec4-4063-b904-7efaed985648).

Code snippet that reproduces the problem

I'm unable to share a 'try' link as the sample code hangs on there too, but this is a small test-case:

<?php declare(strict_types = 1);

trait foo {
	public function getFoo() 
	{
		return new class {
			use foo;
		};
	}	
}

class HelloWorld
{
	use foo;
}

var_dump((new HelloWorld())->getFoo()->getFoo());

And you can verify that this is valid (if bad) code via this link: https://3v4l.org/VpFPP

Expected output

PHPStan should not hang.

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

Yep, I'm very satisfied with what I've seen with PHPStan with my use-cases so far.

The code that triggered this hang in the first place was actually wrong, so in spite of the hanging it still provided me with valuable information.

@herndlm
Copy link
Contributor

herndlm commented May 10, 2022

We already had such things a couple of times in the past, but this one's kind of special. You can then chain-call ->getFoo() theoretically as often as you want, right? Maybe phpstan should just skip such cases. It's a bit weird 😅 I can check that soon.

@ptlis
Copy link
Author

ptlis commented May 10, 2022

Yeah, in theory you should be able chain any number of invocations of getFoo() - though I doubt there are any real-world uses outside this type of contrived scenario.

@herndlm
Copy link
Contributor

herndlm commented May 11, 2022

Currently working on this, so I "fixed" the recursion in FileTypeMapper but now I got another one in NodeScopeResolver which is not a surprise I guess :) still looking into it this is "only" a NodeScopeResolver problem

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#1303

@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 13, 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

Successfully merging a pull request may close this issue.

3 participants