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

False positive: MethodSignatureMustProvideReturnType in __toString() #8557

Open
derrabus opened this issue Oct 9, 2022 · 8 comments
Open

Comments

@derrabus
Copy link

derrabus commented Oct 9, 2022

The MethodSignatureMustProvideReturnType check tells me if I need to add a native return type to a function in order to avoid a deprecation notice on PHP 8.1+.

However, it is also triggered on __toString() although PHP does not trigger a deprecation here.

https://psalm.dev/r/687115a153
https://3v4l.org/uHsSj

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/687115a153
<?php

class MyClass
{
    /** @return string */
    public function __toString()
    {
        return 'foo';
    }
}
Psalm output (using commit 028ac7f):

ERROR: MethodSignatureMustProvideReturnType - 6:21 - Method MyClass::__toString must have a return type signature!

@orklah
Copy link
Collaborator

orklah commented Oct 11, 2022

Thanks for the feedback!

Unfortunately, this issue only exists on the website(and our master branch) for now but it was disabled on 4.x and soon will be disabled on master.

It was causing a lot of false positives for plugin users because Psalm wrongly considers plugin stubs as part of php core. We won't fix your bug for now because we don't know when this issue will be enabled again.

@orklah orklah closed this as completed Oct 11, 2022
@derrabus
Copy link
Author

Sorry, I should've mentioned that I found this issue while testing Psalm 5. Psalm 4 is not affected as far as I can tell.

@derrabus
Copy link
Author

Thank you for your answer!

@orklah
Copy link
Collaborator

orklah commented Oct 11, 2022

Thank you for testing Psalm 5 :) It's very helpful to get feedback!

@derrabus
Copy link
Author

The error is still present in 5.0.0-rc1. Shall we reopen the issue?

@orklah
Copy link
Collaborator

orklah commented Nov 23, 2022

Most definitely!

@orklah orklah reopened this Nov 23, 2022
@orklah
Copy link
Collaborator

orklah commented Nov 24, 2022

@danog do you know what happened here?

We merged your PR for this issue here: #7363
But then we had to revert it here: #7539 because stubs are wrongly qualified as not "user_defined". This was making Psalm enforce wrong return types coming from stubs

But it still end up in master? Do you remember us re-adding it later? Or maybe a mishandling on my part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants