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

Stubs in Reflection.phpstub should implement \Reflector. #6618

Closed
donquixote opened this issue Oct 9, 2021 · 5 comments · Fixed by #7317
Closed

Stubs in Reflection.phpstub should implement \Reflector. #6618

donquixote opened this issue Oct 9, 2021 · 5 comments · Fixed by #7317

Comments

@donquixote
Copy link
Contributor

donquixote commented Oct 9, 2021

https://psalm.dev/r/374b6ca3b8 (EDIT: fixed the link)

When passing a \ReflectionClassConstant object to a function that requires a \Reflector, I get:

ERROR: InvalidArgument - 8:14 - Argument 1 of f expects Reflector, ReflectionClassConstant provided

This works just fine here: https://3v4l.org/iBjV7

The reason, I suspect, is that in Reflection.phpstub, some classes do not implement \Reflector.
This said, I am not really sure how these stubs are supposed to work at all, considering they have only a small subset of the methods available for those classes.

@psalm-github-bot
Copy link

psalm-github-bot bot commented Oct 9, 2021

I found these snippets:

https://psalm.dev/r/374b6ca3b8
<?php

function f(\Reflector $r): \Reflector {
    return $r;
}

function g(\ReflectionClassConstant $r) {
    return f($r);
}

class C {
    const X = 5;
}

g(new \ReflectionClassConstant(C::class, 'X'));
Psalm output (using commit 49abfcb):

ERROR: InvalidArgument - 8:14 - Argument 1 of f expects Reflector, ReflectionClassConstant provided

INFO: MissingReturnType - 7:10 - Method g does not have a return type, expecting Reflector

@donquixote
Copy link
Contributor Author

See also #6619 , it seems that reflection stubs are generally a bit weird..

@orklah
Copy link
Collaborator

orklah commented Oct 9, 2021

We have three sources of knowledge for classes/methods

  • the stubs
  • the callmaps
  • reflection itself

The stubs may not need to be complete if we have intel from callmap.

Please submit a PR for inheritance if it's missing from stubs. Let's see if it fixes your case

@donquixote
Copy link
Contributor Author

Here we go :)

@weirdan
Copy link
Collaborator

weirdan commented Jan 6, 2022

Fixed in #7317

@weirdan weirdan closed this as completed Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants