Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 10, 2025

Closes phpstan/phpstan#13628
Closes phpstan/phpstan#12930

Original bug was

array<mixed~(0|0.0|''|'0'|array{}|false|null)>|mixed~array<mixed, mixed>

resolved into mixed~non-empty-array.

Same exists with something simpler like

array<string>|mixed~array<mixed, mixed>

Because it was converted to mixed ~ (remove(array<mixed, mixed>, array<string>)

While it's true that remove(array<mixed, mixed>, array<string> is a non-empty-array,
it's untrue that array<string>|mixed~array<mixed, mixed> is mixed~non-empty-array.

if ($subtractedType instanceof NeverType) {
if (
$subtractedType instanceof NeverType
|| !$subtractedType->isSuperTypeOf($b)->no()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case checks if we "didn't remove" enough

@ondrejmirtes
Copy link
Member

Looks like it fixes phpstan/phpstan#12930 too

@ondrejmirtes ondrejmirtes merged commit 844f569 into phpstan:2.1.x Oct 10, 2025
539 of 551 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm
Copy link
Contributor

staabm commented Oct 10, 2025

nice!

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.

incorrect inferred type mixed~non-empty-array mixed incorrectly reduced to mixed~string

3 participants