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

"Method M should return static(T) but returns T" for traits #5132

Closed
jmdelehaye opened this issue Jun 3, 2021 · 4 comments
Closed

"Method M should return static(T) but returns T" for traits #5132

jmdelehaye opened this issue Jun 3, 2021 · 4 comments

Comments

@jmdelehaye
Copy link

jmdelehaye commented Jun 3, 2021

Bug report

The use of the "static" keyword as a return type in a Trait does not seem to be handled properly.

Code snippet that reproduces the problem

https://phpstan.org/r/cb077076-faae-4bbb-b865-ab081d95cb52

Expected output

no error

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

Yes, phpstan is a great tool and we use it at the max level on all our projects...
...with a HUGE baseline that we correct as we go :)

@jmdelehaye
Copy link
Author

jmdelehaye commented Jun 3, 2021

It looks like #4860

@ondrejmirtes
Copy link
Member

Hello, thank you for your kind words! This is an expected error and has nothing to do with traits, see: https://phpstan.org/r/cd9bdddf-19cc-414c-a86c-e1b2fbb710d2

The error it's trying to prevent: https://3v4l.org/QvcPB

@jmdelehaye
Copy link
Author

Thank you for your quick reply.

Using the "static" return type was a hack to get IDE autocompletion, but it was a mistake.

I fixed IDE autocompletion using the phpdoc @method tag:
https://phpstan.org/r/7ae38447-e3f9-4b26-8cf3-03954af12f32
https://3v4l.org/eKvEM

@github-actions
Copy link

github-actions bot commented Jul 9, 2021

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 Jul 9, 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