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
Generator expects key type K of int|string, K of int|string given. #7484
Comments
The error message is ambiguously formatted, but it is correct. This is what it's actually saying: Parenthesization should be improved. |
@rvanvelzen Doesn't it boil down to expecting int or a string? Which I'm providing? |
You're not yielding a key of |
That doesn't make sense to me... I'm saying that it returns int or string and that it's the same as what the original array has. Strtoupper and strtolower don't change string into something else, they return string. |
One way of looking at it is that |
I understand what you're saying, it just doesn't make sense to me. That function basically accepts iterable<int|string, mixed> and returns iterable<int|string, mixed>. I used the template only for the added benefit of knowing that if you provide int keys you get int keys back. K is a type, not a value and the type returned is correct. |
Yes, that's why you need a conditional return type and not generics. |
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. |
Bug report
Generator expects key type K of int|string, K of int|string given.
Code snippet that reproduces the problem
https://phpstan.org/r/11599e77-4519-411d-b01f-77a89226a09c
Expected output
No error.
The text was updated successfully, but these errors were encountered: