psalm
psalm copied to clipboard
Psalm consider that B&A<Foo> is more general than A<Foo> but it should be more specific
In https://psalm.dev/r/574fe7f3a5, B&A<Foo> is considered as more general than A<Foo>
Am I wrong or there is no error, because B&A<Foo> should be considered as more specific than A<Foo> ?
I found these snippets:
https://psalm.dev/r/574fe7f3a5
<?php
/**
* @phpstan-template T of object
*/
interface A
{
}
/**
* @phpstan-template T of object
* @phpstan-extends A<T>
*/
interface B extends A
{
}
/**
* @phpstan-template T of object
*/
class Admin
{
/**
* @param A<T> $proxy
* @return A<T>
*/
public function configureQuery(A $proxy): A
{
return $proxy;
}
}
class Foo {}
/**
* @phpstan-extends Admin<Foo>
*/
class SuperAdmin extends Admin
{
public function configureQuery(A $proxy): A
{
\assert($proxy instanceof B);
return $proxy;
}
}
Psalm output (using commit afe85fa):
INFO: LessSpecificReturnStatement - 44:16 - The type 'B&A<Foo>' is more general than the declared return type 'A<Foo>' for SuperAdmin::configureQuery
INFO: MoreSpecificReturnType - 40:47 - The declared return type 'A<Foo>' for SuperAdmin::configureQuery is more specific than the inferred return type 'B&A<Foo>'