Hello.
Since today, PHP Tools for VS Code stopped resolving a PHPDoc generic return type that was working correctly until yesterday.
Extension:DEVSENSE.phptools-vscode
Problem: When a static inherited method has this PHPDoc return type: @return TRepository<static> the IDE no longer shows the inferred return type and autocomplete stops working for chained calls.
If I change it to @return TRepository autocomplete works again, but the generic model type is lost.
Expected behavior: For a class like:
class Pessoa extends TRecord {}
the following call: Pessoa::where(...) should be inferred as: TRepository<Pessoa> and: Pessoa::where(...)->load() should be inferred as: Pessoa[].
Actual behavior:
When using TRepository<static>, the IDE does not show the return type and does not provide proper suggestions for chained methods.
Minimal reproducible example:
/**
* @template TClass of TRecord
*/
class TRepository
{
/**
* @return $this
*/
public function where($variable, $operator, $value, $logicOperator = null)
{
return $this;
}
/**
* @return TClass[]
*/
public function load($criteria = null, $callObjectLoad = true)
{
return [];
}
}
class TRecord
{
/**
* @return TRepository<static>
*/
public static function where($variable, $operator, $value, $logicOperator = null)
{
return (new TRepository())->where($variable, $operator, $value, $logicOperator);
}
}
class Pessoa extends TRecord
{
}
Pessoa::where('id', '=', 1)->where('name', '=', 'test')->load();
Notes: This was working correctly until yesterday. It looks like a regression in PHPDoc generic type resolution when "static" is used as a generic argument.
Please let me know if you need logs or any additional diagnostic information.