bmewburn / vscode-intelephense

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

Templates don't resolve correctly against compatible native return types #2816

Closed lkrms closed 6 months ago

lkrms commented 6 months ago

Describe the bug

In the code below, Intelephense appears not to propagate the type of $ext to the method's return type. $ext resolves correctly in the context of the method itself ($ext->boot() is hinted via IntelliSense 🎉), but Expected type 'Extension'. Found 'T'. is reported against the method's (native) return type.

To Reproduce

<?php

interface Extension
{
    public function boot(): void;
}

class ExtensionFactory
{
    /**
     * @template T of Extension
     *
     * @param class-string<T> $extension
     * @return T
     */
    public function getExtension(string $extension): Extension  // "Expected type 'Extension'. Found 'T'. intelephense(P1006)"
    {
        $ext = new $extension();
        $ext->boot();

        return $ext;
    }
}

Platform and version

v1.10.2 on macOS and Linux

bmewburn commented 6 months ago

I think this is a duplicate of #2770

lkrms commented 6 months ago

Ah, apologies for missing that one. Thank you 🙏🏻