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

Offset access type where array has only one key fails with bound type string not supported #7381

Closed
Seldaek opened this issue Jun 2, 2022 · 2 comments · Fixed by phpstan/phpstan-src#1402
Labels

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Jun 2, 2022

Bug report

Code snippet that reproduces the problem

It appears if the type T has only one key, T[K] fails because K is just a string and perhaps it expects always a union type of strings/keys?

https://phpstan.org/r/f4197fdb-eaef-485c-a5be-d026adf5e6c2

Expected output

No error

cc @rvanvelzen

@rvanvelzen
Copy link
Contributor

You're exactly right - this effectively becomes a constant string bound, which is not supported: https://phpstan.org/r/c28fe2e8-5201-4236-8f94-497fdf28f4c5

The trivial solution is to implement constant string/integer template bounds, given that key-of<T> can only be string or int.

@github-actions
Copy link

github-actions bot commented Jul 9, 2022

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

Successfully merging a pull request may close this issue.

3 participants