Skip to content

Support for list<Foo> type #134

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

Closed
enumag opened this issue Oct 26, 2021 · 1 comment · Fixed by #136
Closed

Support for list<Foo> type #134

enumag opened this issue Oct 26, 2021 · 1 comment · Fixed by #136

Comments

@enumag
Copy link
Contributor

enumag commented Oct 26, 2021

I noticed that TypeResolver currently doesn't support the list type which is generally used as subtype of array<int, Foo>, indicating it's an array that PHP's array_is_list() function would return true.

It's described in more detail in Psalm's documentation for instance: https://psalm.dev/docs/annotating_code/type_syntax/array_types/#lists

From browsing the code it seems this would need to be handled in TypeResolver::resolveCollection().

What do you think about supporting this in this library?

@jaapio
Copy link
Member

jaapio commented Oct 26, 2021

Thanks for reporting this.

I think our generics support can be improved. I'm not sure yet how to do this, but we are definitely open for pr's to help us move forward. When I quickly scan the way psalm treads the list type I think this could be a Pseudo type like we have for strings. Maybe we should remove the check in

if (
!$isArray && !$isIterable
&& (!$classType instanceof Object_ || $classType->getFqsen() === null)
) {
throw new RuntimeException(
$classType . ' is not a collection'
);
}

To have better support for all type definitions containing <> .

Please let me know when you want to help us to improve this library, and build support for the list type. I'm available to help you when needed.

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 a pull request may close this issue.

2 participants