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;
}
}
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 🎉), butExpected type 'Extension'. Found 'T'.
is reported against the method's (native) return type.To Reproduce
Platform and version
v1.10.2 on macOS and Linux