Skip to content

Conversation

rvanvelzen
Copy link
Contributor

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

@ondrejmirtes ondrejmirtes merged commit 4b22f3d into phpstan:1.8.x Sep 22, 2022
@rvanvelzen rvanvelzen deleted the bug-7987 branch September 22, 2022 11:35
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.

should return TypeObject of AbstractA|AbstractB but returns AbstractA|AbstractB
3 participants