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 type becomes array when implementing method with variadic parameter #3195

Closed
bronek89 opened this issue Apr 21, 2020 · 3 comments
Closed

Comments

@bronek89
Copy link

bronek89 commented Apr 21, 2020

Bug report

Hi, I'm not sure how to describe this error, but:
When implementing method with variadic templated type - that type becomes array<int, T>. For example: TKey becomes array<int, TKey>.

/**
 * @template TKey
 * @template TValue
 */
interface A
{
    /**
     * @phpstan-param array<int, TKey> $keys
     * @phpstan-return A<TKey, TValue>
     */
    public function methodName(...$keys): A;
}

/**
 * @template TKey
 * @template TValue
 * @implements A<TKey, TValue>
 */
class AI implements A
{
    /**
     * @phpstan-param array<int, TKey> $keys
     * @phpstan-return A<TKey, TValue>
     */
    public function methodName(...$keys): A
    {
         // return type of parent method is detected as array<int, TKey> 
    }
}

(full examples below)

Am I doing something wrong? :) Or this is a bug?

Code snippet that reproduces the problem

https://phpstan.org/r/1e9e5aab-3494-40bb-ab40-fe58993224af
https://phpstan.org/r/d78732e7-1bbb-41d4-bba6-e7dd6e6fd36c

The same error occurs with variadic syntax TKey ...$keys:
https://phpstan.org/r/25ea56c5-c03b-426d-b274-a0fda1df4b60

"Concrete variadic" types are ok:
https://phpstan.org/r/2ebfc221-b297-4c58-9843-e89f72666b98

Passing int as TKey by @implements does not produce error:
https://phpstan.org/r/6bb97423-efe2-4ed7-b78e-dd334d67e7d2

Expected output

No errors like in https://psalm.dev/r/e8a2f1414d or https://psalm.dev/r/d8ad951558

@ondrejmirtes
Copy link
Member

Hi, yes, variadic generics are not yet supported. Filing under https://github.com/phpstan/phpstan/milestone/9.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@a599eaa

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants