phpstan icon indicating copy to clipboard operation
phpstan copied to clipboard

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

Open ollieread opened this issue 3 years ago • 0 comments

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

ollieread avatar Jul 29 '22 10:07 ollieread