Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

Closes phpstan/phpstan#13777

The issue is that UnionType::getObjectClassReflections was returning [] as soon as one of subtypes returns []...

'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'PHPDoc tag @phpstan-require-extends contains unknown class IncompatibleRequireExtends\SomeClass.',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny to see that test was added with the bug (since SomeClass was existing)

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/Rules/PhpDoc/RequireImplementsDefinitionTraitRule.php was changed but not tested

@ondrejmirtes ondrejmirtes merged commit 1eead47 into phpstan:2.1.x Dec 5, 2025
635 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When one class mentioned by @phpstan-sealed is unknown all classes are incorrectly reputed unknown

2 participants