Skip to content

Incorrect covariant error in final class with methods that return static, when using generics #7717

@ollieread

Description

@ollieread

Bug report

When creating a final class that implements a method from an interface that has the return type static, and when using generics, PHPStan incorrectly reports that the return type of the method in the final class is not covariant with its prototype.

I would ordinarily put this down to some nuance of PHPStan and create a rule to ignore it, but if I change the return type of the implementing method to anything but static, it is no longer valid PHP.

Code snippet that reproduces the problem

Playground (Like my original setup): https://phpstan.org/r/17df6190-a2f8-4f0d-adf6-d54c926091b9
Playground (Simplified): https://phpstan.org/r/8015b1df-f73a-419d-b367-24ef7749fa1e
Test repo: https://github.com/smplphp/phpstan-final-static-covariant-bug

Expected output

No errors

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