Skip to content

[TypeInfo] Handle key-of and value-of types #60655

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

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

mtarld
Copy link
Contributor

@mtarld mtarld commented Jun 3, 2025

Q A
Branch? 7.2
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60643
License MIT

Add missing support for key-of and value-of type.

@stof
Copy link
Member

stof commented Jun 3, 2025

Be careful, there is 2 different value-of supported cases in phpstan and psalm:

  • value-of<T> with T being a BackedEnum type returns the union of all backing values of that enum (which we can generalize to the backing type as done in this PR)
  • value-of<T> with T being an array type returns the type of values in that array (there is also key-of<T> for the equivalent for the key type)

@mtarld
Copy link
Contributor Author

mtarld commented Jun 3, 2025

Oh, didn't know about that, I'll update the PR accordingly, thanks!

@mtarld mtarld force-pushed the fix/type-info-value-of branch from 54460fa to 4c8d14b Compare June 3, 2025 11:57
@mtarld
Copy link
Contributor Author

mtarld commented Jun 3, 2025

Done.

@mtarld mtarld force-pushed the fix/type-info-value-of branch from 4c8d14b to 4457633 Compare June 3, 2025 12:38
@mtarld mtarld changed the title [TypeInfo] Handle value-of type [TypeInfo] Handle key-of and value-of types Jun 3, 2025
@OskarStark
Copy link
Contributor

Looks like a feature to me

@jack-worman
Copy link
Contributor

jack-worman commented Jun 4, 2025

Looks like a feature to me

I consider this a bug because when I upgraded to Symfony 7.3 the TypeInfo component started throwing an exception. This is because 7.3 introduced handling type aliases, and my code had a value-of<T> in it.

So, until this is fixed I have to not use value-of<T> (and have worse static analysis) or not use TypeInfo (and do something 🤷 )

@nicolas-grekas
Copy link
Member

Thank you @mtarld.

@nicolas-grekas nicolas-grekas merged commit 39d4e97 into symfony:7.2 Jun 4, 2025
10 of 11 checks passed
@mtarld mtarld deleted the fix/type-info-value-of branch June 4, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy