Skip to content

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
Development

Successfully merging this pull request may close these issues.

Greater and smaller expressions combined with null in a BooleanOr are incorrectly specified
3 participants