Skip to content

Generic template type bound is lost in ::class #6864

@LastDragon-ru

Description

@LastDragon-ru

Bug report

Seems same as #3263 but for ::class instead of get_class()

<?php declare(strict_types = 1);

class Model {
    
}

/**
 * @template TModel of Model
 */
class ModelHelper {
    /**
     * @var TModel
     */
    private Model $model;

    /**
     * @param TModel $model
     */
    public function __construct(Model $model) {
        $this->model = $model;
    }

    /**
     * @return class-string<TModel>
     */
    public function bug(): string {
        // Method ModelHelper::bug() should return class-string<TModel of Model> but returns class-string<Model>.
        return $this->model::class; 
    }
}

Code snippet that reproduces the problem

(https://phpstan.org/r/6cfdf3cf-423e-45d4-b86c-7664ada4eccb)

Expected output

no error

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

Yep, I've found missed method call 🙈

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions