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
Avoid duplicate in Union type description #2973
Avoid duplicate in Union type description #2973
Conversation
bd6bb86
to
0241e54
Compare
The root issue is in type normalization, not describing UnionType. If two types with the same description come up in a UnionType, it's because they haven't been properly normalized (due to isSuperTypeOf being implemented in a wrong way). See https://phpstan.org/developing-extensions/type-system#type-normalization |
But in case of custom Type with metadata like DQL here, we have the situation
To me it's because the QueryType is templated as
instead of
But I assume this template was not added because it's too complicated for phpdoc, people would end with
|
Alright, I understand it now. But I want a slightly different behaviour - for the most-detailed VerbosityLevel (precise I think) I don't want to unique the types, I want to keep them separate and mark them with a number, so the result is going to be:
Thanks |
Done in 851f7c3 |
(lint job errors) |
Should be ok now |
tests/PHPStan/Type/UnionTypeTest.php
Outdated
'(TFoo of TBar)|null', | ||
'(TFoo of TBar)|null', | ||
], | ||
[ | ||
new UnionType([new QueryType('foo'), new QueryType('bar')]), | ||
'Doctrine\ORM\Query<mixed, mixed>#1|Doctrine\ORM\Query<mixed, mixed>#2', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to add QueryType class here, you can just add the same type twice into UnionType constructor.
ba62e01
to
598f40c
Compare
Thank you. |
This is related to phpstan/phpstan-doctrine#552 (comment)
When a custom Type has
The union Type of this custom Type encounter a weird situation
A simple solution is to call array_unique on the described types.