Generic class with static return type coming from a interface
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 5.9k
- Forks
- 708
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 25
Description
Hi,
I have defined an interface with the return type static. Afterwards I implemented a generic class that uses the interface. When I call the interface method the type is not correctly resolved. See the example:
https://psalm.dev/r/b59404794e
I fix the error by added a doc comment in the class implementation:
class Collection implements CopyInterface {
/** @return static */ # <--- This line solves the problem
public function copy(): static {
// No real implementation
return $this;
}
}
Is this an intended behavior?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Psalm playground example and compare the generic class implementing the interface with and without the @return static annotation. Trace how Psalm resolves static return types through interface implementations; done means the behavior is either corrected so the return type resolves without the annotation or clearly established as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100