psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Shaped array without indexes is inconsistently treated as list

Open AndrolGenhald opened this issue 2 years ago • 1 comments

https://psalm.dev/r/2310609d33

The return type is treated as a list when calling takesList(), but the returned value isn't a list.

I think array shapes without keys should be further restricted to be "sealed" and marked as lists, and the type comparison might need fixed to ensure this works properly.

Related to this, and also some discussions on slack.

AndrolGenhald avatar Jul 18 '22 01:07 AndrolGenhald

I found these snippets:

https://psalm.dev/r/2310609d33
<?php

/** @param list<mixed> $_ */
function takesList(array $_): void {}

/** @return array{int, float} */
function foo(): array
{
    return [1 => 2.0, 0 => 1];
}

takesList(foo());
Psalm output (using commit 8c716f8):

No issues!

psalm-github-bot[bot] avatar Jul 18 '22 01:07 psalm-github-bot[bot]