Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template class in class-string<MyClass<T>> doesn't seem to be recognized #3726

Closed
binarious opened this issue Jul 1, 2020 · 1 comment
Closed
Labels

Comments

@binarious
Copy link
Contributor

binarious commented Jul 1, 2020

A construct of

/** @template T of CrudEntity */
interface CrudNew
{
    /** @param class-string<CrudRequest<T>> $requestClass */
    public function handle(string $requestClass): void;
}

doesn't seem to accept a class string implementing CrudRequest<T>:

https://psalm.dev/r/adda512f6a

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/adda512f6a
<?php

/** @template T of CrudEntity */
interface CrudRequest
{}

interface CrudEntity
{}

/** @implements CrudRequest<Author> */
class AuthorRequest implements CrudRequest
{}

class Author implements CrudEntity
{}

/** @template T of CrudEntity */
interface CrudNew
{
    /** @param class-string<CrudRequest<T>> $requestClass */
    public function handle(string $requestClass): void;
}

class AuthorNew
{
    /** @param CrudNew<Author> $crudNew */
    public function __invoke($crudNew): void
    {
        $crudNew->handle(AuthorRequest::class);
    }
}
Psalm output (using commit 17558a5):

ERROR: InvalidArgument - 29:26 - Argument 1 of CrudNew::handle expects class-string<CrudRequest<T>>, AuthorRequest::class provided

@muglug muglug added the bug label Jul 1, 2020
@muglug muglug closed this as completed in ea82cdc Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants