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

Error recognizing key value in array in case of union #6728

Closed
janbarasek opened this issue Mar 3, 2022 · 4 comments
Closed

Error recognizing key value in array in case of union #6728

janbarasek opened this issue Mar 3, 2022 · 4 comments

Comments

@janbarasek
Copy link

Bug report

PhpStan will incorrectly overwrite the value of the key in the array if it was defined as union.

Snímek obrazovky 2022-03-03 v 15 02 43

Code snippet that reproduces the problem

https://phpstan.org/r/b9b6eddd-b448-4642-bc09-8bfc4555712f

Expected output

In the case of a union of multiple different arrays, the context should correctly identify which array I just used.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Mar 3, 2022

This is basically a duplicate of #6469, but I'm gonna keep this open too.

@ondrejmirtes
Copy link
Member

For a simple fix change the conditon to: https://phpstan.org/r/8c941b81-4c25-4852-9d33-9516666296a9

@phpstan-bot
Copy link
Contributor

@janbarasek After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-22: Offset 'errorReason' does not exist on array{success: false, errorReason: string}|array{success: false, id: int}.
+19: Call to function assert() with true will always evaluate to true.
+19: Offset 'id' on array{success: true, id: int} in isset() always exists and is not nullable.
Full report
Line Error
19 Call to function assert() with true will always evaluate to true.
19 Offset 'id' on array{success: true, id: int} in isset() always exists and is not nullable.

@github-actions
Copy link

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 Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants