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

@rvanvelzen rvanvelzen commented Sep 13, 2022

@rvanvelzen rvanvelzen marked this pull request as ready for review Sep 13, 2022
@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

@ondrejmirtes ondrejmirtes Sep 20, 2022

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

@rvanvelzen rvanvelzen Sep 22, 2022

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

@ondrejmirtes ondrejmirtes Sep 22, 2022

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

@arderyp arderyp Sep 24, 2022

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

@ondrejmirtes ondrejmirtes merged commit 4b22f3d into phpstan:1.8.x Sep 22, 2022
217 of 224 checks passed
@rvanvelzen rvanvelzen deleted the bug-7987 branch Sep 22, 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
3 participants