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

Chained nullsafe method call wrongly induces caller's type #5868

Closed
janedbal opened this issue Nov 1, 2021 · 5 comments · Fixed by phpstan/phpstan-src#752
Closed

Chained nullsafe method call wrongly induces caller's type #5868

janedbal opened this issue Nov 1, 2021 · 5 comments · Fixed by phpstan/phpstan-src#752

Comments

@janedbal
Copy link
Contributor

janedbal commented Nov 1, 2021

Bug report

See snippet, found while upgrading from 0.12.99 to 1.0.0

Code snippet that reproduces the problem

https://phpstan.org/r/208a06db-9004-4c14-96c1-7f4ad80493da

Expected output

No error.

@olsavmic
Copy link

olsavmic commented Nov 2, 2021

@ondrejmirtes Quick fix would be to move NullsafeOperatorHelper::getNullsafeShortcircuitedExpr back to the ruleLevelHelper->findTypeToCheck (enabling it conditionally, as it was done in https://github.com/phpstan/phpstan-src/pull/687/files/ce98dd8699de590e1585e925cc463ca286f4de58#diff-9dace3387909be6cad5cfedf4087102d316daf48f31a033ae258ab119636035b) since the auto-removal now skips the $scope->moreSpecificTypes record created by NodeScopeResolver for original NullsafeMethodCall.

I was not aware of this part and it's quite hard to wrap head around this logic. Perhaps we could get rid of the NullsafeOperatorHelper by passing the moreSpecificType to nested MethodCalls as well?

@jeroennoten
Copy link

Another example that reproduces the problem: https://phpstan.org/r/954e0684-5afd-4c23-bbe5-e9e56d92801d

@olsavmic
Copy link

olsavmic commented Nov 3, 2021

@ondrejmirtes I created a PR with the original "not-ideal but working" solution as I'm pretty sure this bothers many users :/

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src#752

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants