Repository navigation
Add TemplateDeclarationTypeNode for "T of Foo" in generic arguments - #352
Merged
Merged
Conversation
A generic type argument may now declare a template with an upper bound, like class-string-map<T of Foo, T> or array<K of key-of<Config>, Config[K]>. It is read into a TemplateDeclarationTypeNode holding the name and the bound, for every generic type: which types give it a meaning is up to the tool resolving the types. "T as Foo" is read the same way and printed as "T of Foo", like a @template tag. The bound is required, so class-string-map<T, V> and array<T, V> are read as before. Amp-Thread-ID: https://ampcode.com/threads/T-01a22165-e448-7588-8b56-bc4dd19cc3a4
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A generic type argument may now declare a template with an upper bound, like
class-string-map<T of Foo, T>orarray<K of key-of<Config>, Config[K]>. It is read into a newTemplateDeclarationTypeNode(name+bound) inside an ordinaryGenericTypeNode.This is an alternative to #346. Instead of a node specific to
class-string-map, the parser reads the declaration in the arguments of every generic type and leaves which types give it a meaning to the tool resolving the types (in PHPStan,TypeNodeResolver). Soarray<T of Foo>parses, and PHPStan reports it where it means nothing.T as Foois read the same way and printed asT of Foo, like a@templatetag.class-string-map<T, V>andarray<T, V>are read exactly as before, because the parser cannot tell a declaration from a class namedT.covariant of/contravariant ofstay a variance followed by a type namedof.doc/grammars/types.pp3describes it, so GrammarSyncTest and FuzzyTest agree with the parser.Refs #281