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

Split TemplateType::isSubTypeOf() and TemplateType::isAcceptedBy() #1001

Merged
merged 1 commit into from Feb 7, 2022

Conversation

arnaud-lb
Copy link
Contributor

@arnaud-lb arnaud-lb commented Feb 7, 2022

TemplateType::isAcceptedBy() delegates to TemplateType::isSubTypeOf(). Because of this, bounds are compared with isSubTypeOf(), which gives undesirable results in the context of isAcceptedBy().

For instance, ArrayAccess->isSuperTypeOf(Traversable) being maybe causes (T of ArrayAccess)->accepts(Traversable) to be maybe as well.

In this PR I split the implementations of TemplateType::isSubTypeOf() and TemplateType::isAcceptedBy(), so that isAcceptedBy() can compare bounds with accepts().

This fixes phpstan/phpstan#6589

@ondrejmirtes
Copy link
Member

Makes sense, let's 🚢 this :)

@arnaud-lb arnaud-lb marked this pull request as ready for review February 7, 2022 16:49
@arnaud-lb
Copy link
Contributor Author

I've marked the PR as ready 🚢🚢🚢 However I'm not super confident about everything in this PR yet, and I'll be AFK for a few days, so I wouldn't mind if this was not merged immediately.

@ondrejmirtes
Copy link
Member

The worst thing that can happen are infinite recursions. We're not gaining anything by making it sit here, there's at least a chance we will gather some feedback when it's merged and there's something wrong with it :)

In the worst case scenario it can be reverted. There won't be a release for a few days anyway so don't worry too much :)

Thank you.

@ondrejmirtes ondrejmirtes merged commit 35606f9 into phpstan:master Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants