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

Wrong type inference on array when setting values on it #6173

Open
VincentLanglet opened this issue Dec 8, 2021 · 3 comments
Open

Wrong type inference on array when setting values on it #6173

VincentLanglet opened this issue Dec 8, 2021 · 3 comments
Labels
Milestone

Comments

@VincentLanglet
Copy link
Contributor

Bug report

Code snippet that reproduces the problem

(https://phpstan.org/r/183caf26-e741-46be-b8ab-b93af9f082aa)

Expected output

No error, the array should be considered as array{foo?: int, bar?: int}

Did PHPStan help you today? Did it make you happy in any way?

Sure

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 8, 2021
@VincentLanglet
Copy link
Contributor Author

Similar issue https://phpstan.org/r/74a8382c-f6bf-4fca-a378-100ca2568cae

The array is inferred as array{bar: int<min, -1>, foo: int<1, max>}
but foo and bar can never be set in the same time.

Same issue with if/else: https://phpstan.org/r/4941e906-0ee4-462c-9aa7-93c98a9772d7

I can also try to fix it, if you have an idea where I should look @ondrejmirtes

@phpstan-bot
Copy link
Contributor

@VincentLanglet After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
-20: Offset 'foo' on array{bar: int<min, 0>, foo: int<1, max>} in isset() always exists and is not nullable.
+No errors

@phpstan-bot
Copy link
Contributor

@VincentLanglet After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
-21: Offset 'foo' on array{bar: int<min, -1>, foo: int<1, max>} in isset() always exists and is not nullable.
+No errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants