-
Notifications
You must be signed in to change notification settings - Fork 662
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
Issue with template inheritance and overriding method signatures #10010
Conversation
Signed-off-by: Maximilian Bösing <[email protected]>
I'll try to take a look in the next few days :) |
interface PluginManagerInterface | ||
{ | ||
/** | ||
* @template TRequestedInstance extends InstanceType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we support extends
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works flawless if I do not overwrite the method in the abstract class. the issue is adding the object return type which makes it less specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I confirm we don't do anything with the extends keyword so it's just comments as far as Psalm is concerned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it actually seems to work until I add the overridden method with the object return type 🤔 or its just a coincdedence as I do not verify some where if that is actively validated.
So to implement this, I have to focus the extends?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you show an example where psalm behaves differently based on the extends?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I cant. I just know that the way psalm behaves differs once I extend the get
method and narrow the type from mixed to object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you post two snippets so we see the difference exactly? I'm still a bit confused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://psalm.dev/r/e80a63390b
https://psalm.dev/r/442b189bf4
But I am pretty sure that it does not respect the extends
within the template
annotation in method scope but not sure if that is the underlying problem tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've digged a bit deeper and found out that there is a general issue with @inheritdoc
as due to this, templates are completely dropped and therefore the whole type detection seems to be problematic when it comes to assertions.
https://psalm.dev/r/538a0d30d4
I am totally lost here, but thats maybe due to the fact that I spent too much time on other psalm related stuff in the past days.
Would really love to get some help on this but will also try to solve this on my own in the next weeks.
I have no clue how to describe the issue, maybe I am using something wrong or I don't know.
I dived through the code and found out that this code would work if the following check would return true:
\Psalm\Internal\Codebase\Methods::getMethodReturnType
The union comparator returns
false
due to the fact that theTTemplateParam
TRequestedInstance
providesmixed
but should return a super ofInstanceType
due toTRequestedInstance extends InstanceType
andInstanceType
is actually known asPluginInterface
.So I guess I do have to find out why the
TRequestedInstance
is not properly inferred asPluginInterface
as that would probably lead to the expected result.Fun fact, the code works once removing the overriden method
AbstractSingleInstancePluginManager#get
as it narrows the return value frommixed
toobject
which then seems to mess up the whole type detection...Happy if some1 has some little guidance here and can point me in the correct direction. As of now, I'd say the problem is that
TRequestedInstance
is not providingPluginInterface
as it should, but no clue where this should happen.