Skip to content

PHPStan resolves "@return static<T>" to return type "parent<T>" when called from child class #8623

@lkrms

Description

@lkrms

Bug report

PHPStan incorrectly resolves the return type of a static method annotated with @return static<T> to the parent class when called from a child class, and proceeds to report "undefined method" for every subsequent call to a method of the child class.

Using @return static resolves the issue but prevents propagation of type information.

Code snippet that reproduces the problem

https://phpstan.org/r/b4f91405-36ef-463e-bc84-9050eec247ff

Expected output

In the context of a child class with no templated types, static<T> would be invalid, and while handling this scenario robustly may be non-trivial, PHPStan should resolve static<T> correctly in the context of a child class that does specify a templated type. If not, it should report unsupported syntax and/or advise using static, because silently treating it as self<T> results in false negatives.

Did PHPStan help you today? Did it make you happy in any way?

While updating a codebase with generics as first-class citizens (now that I'm using a vscode extension that understands them), I've been very happy with PHPStan's excellent support for scenarios I thought it would struggle with. Thank you for your service!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions