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

False positive: Binary operation "+" between array()|array(...) and array()|array(...) results in an error. #5584

Closed
schlndh opened this issue Sep 2, 2021 · 4 comments · Fixed by phpstan/phpstan-src#657
Labels
Milestone

Comments

@schlndh
Copy link

schlndh commented Sep 2, 2021

Bug report

Phpstan reports an error when concatenating arrays with +. It only seems to happen when the type of the arrays is a union (e.g. $c = ['a' => 5] + ['b' => 6]; does not report an error).

This issue was introduced in 0.12.97, it does not occur in the previous version.

Code snippet that reproduces the problem

https://phpstan.org/r/0fea1806-6978-44a7-b5e9-eed6d2d5660c

Expected output

No errors.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 2, 2021
@ondrejmirtes
Copy link
Member

/cc @staabm Can you look at this? It's a bit weird to me because the code handling the unions is there https://github.com/phpstan/phpstan-src/blob/2ba9332d29c1acdde0f85a2781308d2e8972f00e/src/Analyser/MutatingScope.php#L1325-L1344 but maybe it's unreachable with the new range math...

You can test this in NodeScopeResolverTest, the operation type should not be ErrorType...

@staabm
Copy link
Contributor

staabm commented Sep 2, 2021

I can have a look at the beginning of next week

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#657

@github-actions
Copy link

github-actions bot commented Oct 5, 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 Oct 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants