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_keys with > 1 argument returns too-broad type #11928

Open
ManuelHu opened this issue Oct 28, 2024 · 1 comment · May be fixed by phpstan/phpstan-src#3590
Open

array_keys with > 1 argument returns too-broad type #11928

ManuelHu opened this issue Oct 28, 2024 · 1 comment · May be fixed by phpstan/phpstan-src#3590

Comments

@ManuelHu
Copy link

ManuelHu commented Oct 28, 2024

Bug report

array_keys would never return a key that is not already part of the (narrowed) key type.

a simple first fix (i suppose): just removing this check: https://github.com/phpstan/phpstan-src/blob/612ee600d58315b23506a8a148b0100597b7661b/src/Type/Php/ArrayKeysFunctionDynamicReturnTypeExtension.php#L30

While this might not fix all cases, it would certainly fix the cases of narrowed array-key types to int or string? (*)

(*) with the known caveat of the internal type conversion of integer strings, of course

Code snippet that reproduces the problem

https://phpstan.org/r/f43ddd65-69db-4d3e-acb4-9d2689e5f5b3

Expected output

8: Dumped type: list<int>
11: Dumped type: list<int>

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

No response

@staabm
Copy link
Contributor

staabm commented Oct 28, 2024

a simple first fix (i suppose): just removing this check

You could give it a try and see how the test suite results look like

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

Successfully merging a pull request may close this issue.

2 participants