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

Add support of docblock method using parent keyword #7414

Merged
merged 4 commits into from Jan 24, 2022

Conversation

vincent4vx
Copy link
Contributor

See: #7411

Currently, when using parent::, psalm consider the call as static, so resolve from pseudo_static_method instead of pseudo_method.
This fix will forward to instance method analyser when parent:: call is detected, in instance method context, and if the method is not declared.

@orklah
Copy link
Collaborator

orklah commented Jan 17, 2022

The shepherd error is surprising because the function does not actually exists(removed in phpunit 9) so the suppression should still be used.

On another topic, I didn't expect you'd add a new condition here: https://github.com/vimeo/psalm/pull/7414/files#diff-eb58cff4a0b42fdcb5bb7462a60e099ef97f49c766c10c1086b50f63bc1251f3R653

I was looking at two possibilities on my end:

Those two seemed more appropriate for this kind of change. I may be wrong here so if you have a legit reason not to use those, go ahead

@vincent4vx
Copy link
Contributor Author

Adding the check of pseudo_methods is not enough, because the __callstatic method will be checked, which is not expected for parent:: call, because it should use __call instead. Also, in case of undeclared pseudo method, types should be resolved using __call and not __callstatic (I'll add a test case).

And for the second option, method existence and visibility is checked before, so it's not possible to implements pseudo method here.

Maybe my condition is not at the correct place ?

Interesting behavior on PHP : https://3v4l.org/tfYli
When __call is not found, the call will be forwarded to __callStatic 🤷

@orklah
Copy link
Collaborator

orklah commented Jan 19, 2022

I'm fine with the answer :)

Can you check why there is an error on shepherd for a non-existing method? After this is fixed, this seems fine to merge

@vincent4vx
Copy link
Contributor Author

Maybe a cache issue ? Merge of branch 4.x has resolve the error.

@orklah
Copy link
Collaborator

orklah commented Jan 20, 2022

There's no cache on our CI :p

And no, it disappeared after a rebase because I merged this: #7435

But it's concerning that the error was here in the first place. Can you revert my change on your end to check why the error was here?

@vincent4vx
Copy link
Contributor Author

Oh, it's a bug of my feature...

Because the method do not exists on parent, it will be forwarded to instance method call.
But the static type (i.e. type of $this) will be used instead of the parent one, so the method will exist because it's declared on child with the same name...

So, this code will not raise UndefinedMethod :

<?php
                    class A {}
                    class B extends A {
                        public function foo(): string {
                            return parent::foo();
                        }
                    }

@vincent4vx vincent4vx marked this pull request as draft January 20, 2022 10:37
@vincent4vx vincent4vx marked this pull request as ready for review January 24, 2022 08:23
@orklah orklah added release:feature The PR will be included in 'Features' section of the release notes and removed PR: Needs work labels Jan 24, 2022
@orklah
Copy link
Collaborator

orklah commented Jan 24, 2022

Thanks!

@orklah orklah merged commit f1c4b62 into vimeo:4.x Jan 24, 2022
@vincent4vx vincent4vx deleted the call-docblock-method-using-parent branch January 24, 2022 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature The PR will be included in 'Features' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants