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 type specification of subtractable types #1028

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Feb 21, 2022

Closes phpstan/phpstan#6672
Related to phpstan/phpstan#6674

Not quite happy yet about the sorting, I feel there is a better way to handle this, somehow in the loop maybe, but I can't wrap my head around it right now.

The previous assumption was incorrect, it is not enough to just swap the sureTypes and sureNotTypes, as this can easily lead to a NeverType.
In this change a SubtractableType is created instead for both which makes retains more type information in follow-up operations like union or intersect.
@herndlm herndlm force-pushed the improve-type-specification-of-subtractable-types branch from 1ab2878 to 7438b86 Compare February 21, 2022 20:57
Converts non-SubtractableTypes to SubtractableTypes in union to not loose subtracted type information.
Sorts the SubtractableTypes in intersect to not loose subtracted type information if SubtractableTypes are intersected where not all of them have subtracted types configured.
@herndlm herndlm force-pushed the improve-type-specification-of-subtractable-types branch from 7438b86 to 2237c47 Compare February 21, 2022 21:08
@herndlm herndlm marked this pull request as ready for review February 21, 2022 21:49
@ondrejmirtes ondrejmirtes merged commit 68e6443 into phpstan:master Feb 22, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm herndlm deleted the improve-type-specification-of-subtractable-types branch February 22, 2022 20:43
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