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

Fix/issue 5903 #1051

Merged
merged 5 commits into from Mar 6, 2022
Merged

Fix/issue 5903 #1051

merged 5 commits into from Mar 6, 2022

Conversation

rajyan
Copy link
Contributor

@rajyan rajyan commented Mar 6, 2022

@@ -823,6 +823,9 @@ private function processStmtNode(
if (!$isIterableAtLeastOnce->no()) {
$throwPoints = array_merge($throwPoints, $finalScopeResult->getThrowPoints());
}
if (!$scope->getType($stmt->expr)->isArray()->yes()) {
Copy link
Member

Choose a reason for hiding this comment

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

What about this instead?

!(new ObjectType(\ArrayAccess))->isSuperTypeOf($scope->getType($stmt->expr)-)->no()

Copy link
Member

Choose a reason for hiding this comment

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

This will make it not report a false positive for example array|null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I'll look into it.

@ondrejmirtes
Copy link
Member

Sorry, I used a wrong type in the review and fixed it myself :) 83e4284 (ArrayAccess has nothing to do with iteration).

Thank you.

@ondrejmirtes ondrejmirtes merged commit d32942a into phpstan:master Mar 6, 2022
@rajyan
Copy link
Contributor Author

rajyan commented Mar 6, 2022

@ondrejmirtes

ArrayAccess has nothing to do with iteration

Oh, you are right. Sorry that I couldn't notice it. I’m wondering why did the tests passed in local.

@ondrejmirtes
Copy link
Member

Because these objects might implement ArrayAccess in a subclass :) (They're not final.) So the assumption an exception might be thrown is still correct.

@rajyan
Copy link
Contributor Author

rajyan commented Mar 6, 2022

I see. Thank you for clarifying.

@rajyan rajyan deleted the fix/issue-5903 branch March 6, 2022 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants