Skip to content

Conversation

arnaud-lb
Copy link
Contributor

Fixes phpstan/phpstan#5591

Normally, a UnionType A accepts an other UnionType B if every member of B is accepted by A.

This does not hold if B is a TemplateUnionType: If B is a TemplateUnionType and A contains B, then no member of B will be accepted by B itself, and A will not accept B as a result.

For UnionType::accepts(TemplateUnionType) to work, we must treat it as a non-UnionType.

@arnaud-lb arnaud-lb force-pushed the bug-5591 branch 2 times, most recently from 176f15f to e023e2c Compare February 4, 2022 11:27
@ondrejmirtes
Copy link
Member

I love this! This is gonna pull out a huge thorn out of my heel! (Yeah, that's a Czech saying)

Feel free to mark it as ready for merge :)

@arnaud-lb arnaud-lb marked this pull request as ready for review February 4, 2022 12:37
@arnaud-lb
Copy link
Contributor Author

We have a very similar saying in France: "pull a thorn out of my foot " 😄

I've marked the PR as ready for merge 👍

@ondrejmirtes ondrejmirtes merged commit 9512513 into phpstan:master Feb 4, 2022
@ondrejmirtes
Copy link
Member

Thank you! Can't wait what other issues this fixes, the bot will find out 😊

@arnaud-lb
Copy link
Contributor Author

This created a regression: int|float is not a super type of T of int|float anymore. I'm looking into this.

@arnaud-lb arnaud-lb mentioned this pull request Feb 4, 2022
@VincentLanglet
Copy link
Contributor

Hi @arnaud-lb, maybe you can help me on an issue between Tempalte type and Intersection type.
phpstan/phpstan#5336

I've made #585 but ondrej didn't feel the solution as right, WDYT ? Do you see a better way ?

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.

Union Type + Nullable yields "Expects TEntity(A|B)|null, TEntity(A|B)|null given"
3 participants