psalm icon indicating copy to clipboard operation
psalm copied to clipboard

`MethodSignatureMismatch` when concrete class implements interface with return type `static`.

Open simondeeley opened this issue 5 years ago • 2 comments

Given the following pseudo-code:

interface FooInterface
{
    public static function newFoo(): static;
}

class Foo implements FooInterface
{
    public static function newFoo(): static
    {
         $foo = new static();
         return $foo;
    }
}

PHP natively resolves the inheritance and understands that when FooInterface is implemented it, the method FooInterface::newFoo will return an instance of the concrete class, in this case an instance of Foo.

However, Psalm reports MethodSignatureMismatch citing Foo::newFoo returns Foo but was expecting FooInterface, which is technically true but it should also not report any error due to the interface being implemented correctly as far as PHP is concerned.

simondeeley avatar Jun 17 '21 08:06 simondeeley

Hey @simondeeley, can you reproduce the issue on https://psalm.dev ?

psalm-github-bot[bot] avatar Jun 17 '21 08:06 psalm-github-bot[bot]

Closing as non reproduced

orklah avatar Nov 14 '21 18:11 orklah