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

Improve inferring the "final" static type when calling static methods inside a different class #8249

Merged
merged 7 commits into from Jul 14, 2022

Conversation

someniatko
Copy link
Contributor

@someniatko someniatko commented Jul 12, 2022

fixes #8200

After some insane debugging and trying to wrap my head around it, I found the reason it behaves improperly.

When calling a static method of some class, there are two possibilities:

  1. in the static method itself there might be something like @return Collection<static>, that means static is defined by the static method which we are calling.
  2. this static method is parameterized with a template like @return Collection<T>, but the class which CALLS it can have something like @return Collection<static>. So static is defined by the CALLING code, not the CALLED. In this case, Psalm behaved incorrectly, because it always assumed only the 1st case.

I have to move the test case somewhere (for now it's a separate class), please give a hint.

… static methods inside a different class

differentiate between `static` defined in a class which CALLS a given static method, and `static` defined in the method which IS CALLED.
@AndrolGenhald
Copy link
Collaborator

I have to move the test case somewhere (for now it's a separate class), please give a hint.

It looks like ClassTest has some other static stuff like allowFinalReturnerForStatic and intersectWithStatic, so I'd just put it there. Test organization isn't the best...

@someniatko someniatko marked this pull request as ready for review July 12, 2022 18:45
@AndrolGenhald AndrolGenhald added the release:fix The PR will be included in 'Fixes' section of the release notes label Jul 12, 2022
@someniatko
Copy link
Contributor Author

meh, when moving test cases I added them to "invalid code" section instead of "valid code"

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jul 13, 2022

Please indent the test code one level past the <?php tag to match the other tests. LGTM after that's done.

@AndrolGenhald AndrolGenhald merged commit cac9ec9 into vimeo:4.x Jul 14, 2022
@AndrolGenhald
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generics + static = invalid type inference
2 participants