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

How to fix "Unable to resolve the template type T" issue in library #3849

Closed
pkruithof opened this issue Sep 9, 2020 · 4 comments
Closed

Comments

@pkruithof
Copy link

Support question

In a recent update, Doctrine added psalm/phpstan annotations, which now makes phpstan find the following error:

https://phpstan.org/r/e462e0f9-abc4-44bc-8a9a-80aca2717980

I've tracked down the change that most likely causes this, and it seems the Doctrine people could not fix this error so they put this error in the ignore section: https://github.com/doctrine/dbal/pull/3977/files#diff-0847156bd64b0de0f4d91da2394ec0e8R89-R92

My question is: what is this error exactly, is there a way to fix or work around it and if not: do I really need to ignore an error caused by a third-party library?

@ondrejmirtes
Copy link
Member

The full PHPDoc of the method is:

     * @param  array{wrapperClass?: class-string<T>} $params
     * @param Configuration|null                    $config       The configuration to use.
     * @param EventManager|null                     $eventManager The event manager to use.
     *
     * @throws Exception
     *
     * @phpstan-param mixed[] $params
     * @psalm-return ($params is array{wrapperClass:mixed} ? T : Connection)
     * @template T of Connection

So the T is there for the conditional @psalm-return tag. Not sure why the @param for $params is overriden for PHPStan with @phpstan-param mixed[] $params but the result is that PHPStan sees @template T of Connection but the T isn't present in @param so it doesn't have a way to infer what T should be. The signature is basically incomplete and broken from the point of view of PHPStan.

The correct way to fix this would be either to:

  1. Remove @phpstan-param mixed[] $params and see what error it causes and what's the root issue, report it to PHPStan's issue tracker (here) and have it fixed :)
  2. ...or add @phpstan-return Connection without any T involved which should already have been there in the first place...

The easiest way is to send a PR to doctrine/dbal with my 2nd suggestion, they should accept it.

@pkruithof
Copy link
Author

Will do, thank you for clarifying 👍

@pkruithof pkruithof mentioned this issue Sep 9, 2020
16 tasks
@ondrejmirtes
Copy link
Member

I realize that @phpstan-return Collection might still not help to get rid of the issue so maybe 1) with some investigation involved might be a better bet.

@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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants