Fix UnionType::getObjectClassReflections#4541
Conversation
| 'Learn more at https://phpstan.org/user-guide/discovering-symbols', | ||
| ], | ||
| [ | ||
| 'PHPDoc tag @phpstan-require-extends contains unknown class IncompatibleRequireExtends\SomeClass.', |
There was a problem hiding this comment.
Funny to see that test was added with the bug (since SomeClass was existing)
52264b1 to
14257a0
Compare
ondrejmirtes
left a comment
There was a problem hiding this comment.
I think the behaviour of UnionType is correct here. We do pickFromTypes for everything. Once the union type is for example Foo|null, both getObjectClassNames and getObjectClassReflections should return an empty array.
But I don't understand how returning an empty array can cause an error message to appear. Looks like something else needs fixing, like the rule.
Looks like RequireExtendsCheck has some complicated logic I didn't write. The logic there using getObjectClassNames and getObjectClassReflections and trying to map something between them is definitely too complicated and suspicious.
bc4c558 to
c6709b6
Compare
ondrejmirtes
left a comment
There was a problem hiding this comment.
src/Rules/PhpDoc/RequireImplementsDefinitionTraitRule.php was changed but not tested
|
Thank you! |
Closes phpstan/phpstan#13777
The issue is that
UnionType::getObjectClassReflectionswas returning[]as soon as one of subtypes returns[]...