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

Improve intersection of generic class string #1724

Merged
merged 1 commit into from Sep 22, 2022

Conversation

rvanvelzen
Copy link
Contributor

@arderyp
Copy link

arderyp commented Sep 13, 2022

thanks for posting this @rvanvelzen !

assertType('class-string<Bug4875\Blah>&class-string<Bug4875\Mock>', $mock::class);
assertType('class-string<Bug4875\Blah>&class-string<Bug4875\Mock>', get_class($mock));
assertType('class-string<Bug4875\Blah&Bug4875\Mock>', $mock::class);
assertType('class-string<Bug4875\Blah&Bug4875\Mock>', get_class($mock));
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain this a bit? Why class-string<Bug4875\Blah>&class-string<Bug4875\Mock> and class-string<Bug4875\Blah&Bug4875\Mock> aren't equivalent and why this change fixes phpstan/phpstan#7987? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The most important fix is collapsing class-string<T of A|B>&class-string<A> into class-string<T of A>. This allows inferring T more reliably.

Semantically they represent the same thing, and since the collapsed form improves template type inference I think it's better to collapse it.

Copy link
Member

Choose a reason for hiding this comment

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

Nice, thank you!

Copy link

Choose a reason for hiding this comment

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

thank you both! I will test soon and report back if there are any issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants