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

Is [ 0 => 0, 1 => 1 ] a valid list ? #3925

Closed
someniatko opened this issue Aug 3, 2020 · 4 comments
Closed

Is [ 0 => 0, 1 => 1 ] a valid list ? #3925

someniatko opened this issue Aug 3, 2020 · 4 comments

Comments

@someniatko
Copy link
Contributor

https://psalm.dev/r/73fe3f58d1

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/73fe3f58d1
<?php

/** @param list $list */
function takesList(array $list): void {}

takesList([ 0 => 0, 1 => 1 ]);
Psalm output (using commit 7fc4a85):

INFO: UnusedParam - 4:26 - Param $list is never referenced in this method

ERROR: InvalidArgument - 6:11 - Argument 1 of takesList expects list<mixed>, array{0: int(0), 1: int(1)} provided

@weirdan weirdan added the bug label Aug 3, 2020
@muglug muglug removed the bug label Aug 3, 2020
@muglug
Copy link
Collaborator

muglug commented Aug 3, 2020

Nah, leave out the keys and this passes – I don't consider this a bug

@muglug muglug closed this as completed Aug 3, 2020
@someniatko
Copy link
Contributor Author

@muglug Well, yeah, it is obvious that it would pass if you leave out the keys. You have unit tests for this after all. I did not mention this is a bug report, by the way. This issue is more like of question type - I've just asked whether [ 0 => 0, 1 => 1 ] is a valid list in the Psalm type system, or not. If it is not, it would be very nice to know the reason why - maybe it's documented somewhere.

A possible outcome is that it is actually a list as defined by the docs (and common sense, imo), but Psalm doesn't infer that because it's technically hard to implement. In such case i would suggest "bug" badge to stay, and a "wontfix" badge to be added.

Another outcome is that [ 0 => 0, 1 => 1 ] is not a list. Then i suggest it's a documentation issue because, at least I failed to find anything proving it's not.

@someniatko
Copy link
Contributor Author

BTW, the reason I have asked this issue-question is because earlier I was explaining here doctrine/collections#242 (comment) the concept of list (vs array) to a, presumably, Doctrine contributor. However, now I feel myself a bit guilty because probably my explanation is wrong.

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

No branches or pull requests

3 participants