bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.6k stars 93 forks source link

Method not found when created class is passed in as a generic #2961

Open Indeedornot opened 1 month ago

Indeedornot commented 1 month ago

Describe the bug I am attempting to for the time being try to remove phpstan issues from issue #11398 Phpstan however the generic template parameter of Enumerable is not properly inferred by intelephense

To Reproduce

<?php

/**
 * @template TClass
 * @template TKey
 * @template TValue
 */
interface Enumerable
{
    /** @return TClass<TKey, TValue> */
    public function unique();
}

/**
 * @template TKey
 * @template TValue
 * @implements Enumerable<Collection, TKey, TValue> // I have attempted static, Collection, 'Collection'
 */
class Collection implements Enumerable
{
    public function __construct(private array $items) {}

    public function unique()
    {
        $it = array_unique($this->items);
        return new static($it);
    }

    public function getItems(): array
    {
        $k = (empty($this->items) ? $this : $this->unique());
        return $k->getItems(); //method not found
    }
}

Expected behavior return type of $this->unique() is properly inferred from phpdocs

Screenshots If applicable, add screenshots to help explain your problem. image

Platform and version v1.11.5 Windows 11 23H2 VScode 1.91.1

bmewburn commented 1 month ago

In the linked phpstan ticket it's suggested to just use static. Does that work? Resolving a template that has templated type args is not supported. I don't think psalm or phpstan support this either.

/** @return static */
    public function unique();