psalm
psalm copied to clipboard
Shaped array without indexes is inconsistently treated as list
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.
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!