Skip to content

Regression in 2.1.1 with generics #12386

@staabm

Description

@staabm

Bug report

since 2.1.1 we see a regression which per bisect is caused by phpstan/phpstan-src@a063119

I am not yet able to reproduce the problem in a small repro, but the essence is that in a call like the returned generic type is used from a baseclass, instead of a overridden one.

function doFoo() {
    $landMapper = new Application_Model_Mapper_Land();
    \PHPStan\dumpType($landMapper->fetchAllActivePrependDefault(12));
}

dumpType before the broken commit:
Clx_Model_Iterator<Application_Model_Land>

now broken: Clx_Model_Iterator<Clx_Model_Abstract>

the sources look like

/**
 * @template T of Clx_Model_Abstract
 */
abstract class Clx_Model_Mapper_Abstract
{}

/**
 * @template T of Application_Model_Land
 *
 * @extends  Clx_Model_Mapper_Abstract<T>
 */
class ClxProductNet_Model_Mapper_Land extends Clx_Model_Mapper_Abstract
{
    /**
     * @param int $defaultLandid
     *
     * @return Clx_Model_Iterator<T>
     */
    public function fetchAllActivePrependDefault($defaultLandid): Clx_Model_Iterator
    {}
}

/**
 * @template T of \Application_Model_Land
 *
 * @extends  ClxProductNet_Model_Mapper_Land<T>
 */
final class Application_Model_Mapper_Land extends ClxProductNet_Model_Mapper_Land
{
}

/**
 * @template T of \Clx_Model_Abstract
 *
 * @implements Iterator<T>
 */
final class Clx_Model_Iterator implements Countable, Iterator
{}

abstract class Clx_Model_Abstract implements Stringable
{}

class ClxProductNet_Model_Land extends Clx_Model_Abstract
{}

final class Application_Model_Land extends ClxProductNet_Model_Land
{}

Code snippet that reproduces the problem

No response

Expected output

Clx_Model_Iterator<Application_Model_Land>

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

No response

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