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

Array key type isn't reduced based on conditions, but value type is #4910

Closed
dktapps opened this issue Apr 27, 2021 · 3 comments
Closed

Array key type isn't reduced based on conditions, but value type is #4910

dktapps opened this issue Apr 27, 2021 · 3 comments
Labels
Milestone

Comments

@dktapps
Copy link
Contributor

dktapps commented Apr 27, 2021

Bug report

In the below example, an array is populated using the same keys and values. The values are correctly inferred to be limited to 2|3|4|5, but the keys are not, resulting in a spurious error.

Code snippet that reproduces the problem

https://phpstan.org/r/d2f07757-a48b-43ed-a27f-87cdd012922a

Expected output

No error should be reported.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Apr 27, 2021
@phpstan-bot
Copy link
Contributor

@dktapps After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-33: Dumped type: array<int, 2|3|4|5>
-34: Property Vine::$faces (array<2|3|4|5, 2|3|4|5>) does not accept array<int, 2|3|4|5>.
+33: Dumped type: array<2|3|4|5, 2|3|4|5>
Full report
Line Error
33 `Dumped type: array<2

@dktapps
Copy link
Contributor Author

dktapps commented Jan 9, 2022

Nice. Looks like this can be closed pending regression tests.

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

No branches or pull requests

3 participants