Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Dec 19, 2025

No description provided.

@staabm staabm marked this pull request as ready for review December 19, 2025 17:55
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

unset($otherVariableTypeHolders[$variableExprString]);
}

if (count($otherVariableTypeHolders) > 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the loop this array is reduced one offset at a time, which only makes sense if we check afterwards whether $otherVariableTypeHolders contained elements which were not contained in $variableTypeHolders

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 write a failing test against this? Or is it just about performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think I need to come up with a test. looks like a bug to me.

not perf related, just stumbled over it, while looking into #4640 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you write a failing test against this? Or is it just about performance?

I looked into it and tried. I think a case where $other has more types/conditions than $this cannot happen, because in all cases where we call MutatingScope->equals() we do it like $bodyScope->equals($prevScope), meaning we compare a generalized scope (one with reduced information) with one with more information.

this means the scope we get as parameter will always have less information than $this so the theoretical case this PR tried to fix can never happen. but this also means there is dead code in the method, which I now have deleted.

unset($otherVariableTypeHolders[$variableExprString]);
}

if (count($otherVariableTypeHolders) > 0) {
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 write a failing test against this? Or is it just about performance?

@ondrejmirtes ondrejmirtes merged commit e453085 into phpstan:2.1.x Dec 20, 2025
636 of 640 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the fix34 branch December 20, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants