-
-
Notifications
You must be signed in to change notification settings - Fork 916
Type alias imports in traits do not work #5091
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
Comments
@Seldaek After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
33: Property Monolog\Handler\Handler::$foo has unknown class Monolog\Processor\Record as its type.
-38: Return typehint of method Monolog\Handler\Handler::foo() has invalid type Monolog\Processor\Record.
+38: Method Monolog\Handler\Handler::foo() has invalid return type Monolog\Processor\Record.
39: Method Monolog\Handler\Handler::foo() should return Monolog\Processor\Record but returns array<string, string>. Full report
|
I got the same. Should we be able to define types in traits and use them elsewhere or not? edit: Defining a |
another example: https://phpstan.org/r/b07cd15e-abad-4f73-a077-bc4c56df24fe |
Wanted to add a new issue but found this one which seems to be the same underlying issue:
Another example showing the difference when using a trait and when using classes https://phpstan.org/r/a3d8e137-cb3b-40aa-ac5c-31d13f5368dc @Seldaek did you find a workaround for this issue by any chance ? |
Nope I resolved this by using value objects and removing type aliases :) |
I'm experiencing the same issue. (https://phpstan.org/r/3a11ea33-8d1e-4928-9266-bfe23b3341ec) |
I think I've just run into this problem, here's another example of this https://phpstan.org/r/cefffe00-ce91-42c6-9b2d-feaf723fb4e9 |
Has anyone found a solution? |
Fixed: phpstan/phpstan-src@60021c2 |
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. |
Bug report
It appears that type aliases get resolved from the scope of the class they are used in, and not from the trait's main docblock.
Code snippet that reproduces the problem
https://phpstan.org/r/fb90214f-4b8d-4f62-87b9-1680ee2afcfa
Expected output
No error.
The text was updated successfully, but these errors were encountered: