Skip to content

Support bounded template in class-string-map<T of Foo, V> - #346

Closed
Debasishhh wants to merge 4 commits into
phpstan:2.4.xfrom
Debasishhh:class-string-map-bound
Closed

Debasishhh wants to merge 4 commits into
phpstan:2.4.xfrom
Debasishhh:class-string-map-bound

Conversation

@Debasishhh

Copy link
Copy Markdown

Closes #281.

class-string-map<T of Foo, T> (and T as Foo) now parses into a new ClassStringMapTypeNode holding a TemplateTagValueNode for the key template plus the value type, same idea as the template types on generic callables. As discussed above, this is a one-off for class-string-map: array<T of Foo> and other generics still error out, and class-string-map<T, V> without a bound stays a GenericTypeNode.

Updated the grammars too so GrammarSyncTest/FuzzyTest agree with the parser.

@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you, I will think about this and possible alternatives next week.

@ondrejmirtes

ondrejmirtes commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

I gave it a bit more thought and decided for a different direction: #352

It will allow us to use similar approach in array keys in a much more general way, covering more scenarios people might find useful.

class-string-map<T of Foo, T> will be just an alias for array<T of class-string<Foo>, new<T>>.

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 this pull request may close these issues.

support for class-string-map<T of Foo>

2 participants