Skip to content

Type with nested generic parameter is not possible to resolve #4642

@hrach

Description

@hrach

Bug report

When there is a nested generic parameter, resolution from subtype string-class is not done.

interface IEntity {}
/** @template E of IEntity */
interface IRepository {}

interface I {
	/**
 	* Returns repository by repository class.
 	* @template E of IEntity
 	* @template T of IRepository<E>
 	* @phpstan-param class-string<T> $className
	* @phpstan-return T
 	*/
	function getRepository(string $className): IRepository;
}

class User implements IEntity {}
/** @implements IRepository<User> */
class UsersRepository implements IRepository {}

function test(I $model): void {
	$model->getRepository(UsersRepository::class);
}

Results to Unable to resolve the template type T in call to method Nextras\Orm\Model\IModel::getRepository(). Changing the getRepository signature to @template T of IRepository (removed <E>) helps but its not correct and produce error about missing the IRepository generic parameter.

Code snippet that reproduces the problem

https://phpstan.org/r/4b0bfe9f-4e01-4067-b4fb-e65c11e9da57

Expected output

Ability to resolve return type to AuthorsRepository instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions