bmewburn / vscode-intelephense

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

`@template-implements` not recognized for `IteratorAggregate` #2854

Closed distantnative closed 5 months ago

distantnative commented 5 months ago

Describe the bug Trying to implement a collection base class that allows for narrowing the type hints for classes that extend it. But the templating docblock comments don't seem to be picked up correctly.

To Reproduce

/**
 * @template TValue
 * @template-implements IteratorAggregate<string, TValue>
 */
class A implements IteratorAggregate
{
    /**
     * @var array<string, TValue>
     */
    public array $data = [];

    public function __construct(array $data = [])
    {
        $this->data = $data;
    }

    /**
     * Get an iterator for the items.
     * @return ArrayIterator<string, TValue>
     */
    public function getIterator(): ArrayIterator
    {
        return new ArrayIterator($this->data);
    }
}

/**
 * @template-extends A<C>
 */
class B extends A
{
}

class C
{
}

$collection = new B();

foreach ($collection as $value) {
    echo $value; // @var mixed $value
}

Expected behavior $value inside the loop should be recognized as instance of C

Platform and version macOS 14.4 VSCode 1.88.0 Intelephense v1.10.4

Same markup works with https://www.devsense.com/en - but I'd prefer to stick with intelephense

bmewburn commented 5 months ago

The example works for me. Is there any further example or info you can add to reproduce the issue? One thing to check is that there are not multiple classes of same name in the workspace.

Screenshot from 2024-04-11 16-25-25

distantnative commented 5 months ago

Oh man, I just spotted a typo which make it fail. Thanks for the super quick reply 🙏 and sorry for the confusion