If a type is restricted to non-empty-array, a shaped array should be allowed: https://psalm.dev/r/c8fe243f5f
Appending to the list child of a shaped array with a value-restricted param appears to alter the parent type from the initial shaped array to a non-empty-array: https://psalm.dev/r/f24c852ae9
I found these snippets:
https://psalm.dev/r/c8fe243f5f
<?php
/** @param non-empty-array $_bar */
function foo(array $_bar) : void { }
/** @var array{0:list<string>, 1:list<int>} */
$bar = [[], []];
foo($bar);
Psalm output (using commit 7a65eb1):
ERROR: ArgumentTypeCoercion - 8:5 - Argument 1 of foo expects non-empty-array<mixed, mixed>, parent type array{0: list<string>, 1: list<int>} provided
https://psalm.dev/r/f24c852ae9
<?php
class Bar {
/** @var array{0: list<string>, 1:list<string>} */
private $baz = [[], []];
/**
* @param 0|1 $index
*/
public function append(string $str, int $index) : void {
$this->baz[$index][] = $str;
}
}
Psalm output (using commit 7a65eb1):
ERROR: PropertyTypeCoercion - 11:4 - $this->baz expects 'array{0: list<string>, 1: list<string>}', parent type 'non-empty-array<int, list<string>>' provided
@muglug https://psalm.dev/r/f24c852ae9 is still bugged
I found these snippets:
https://psalm.dev/r/f24c852ae9
<?php
class Bar {
/** @var array{0: list<string>, 1:list<string>} */
private $baz = [[], []];
/**
* @param 0|1 $index
*/
public function append(string $str, int $index) : void {
$this->baz[$index][] = $str;
}
}
Psalm output (using commit 887a635):
ERROR: PropertyTypeCoercion - 11:4 - $this->baz expects 'array{0: list<string>, 1: list<string>}', parent type 'non-empty-array<int, list<string>>' provided
That's a different bug, more succinctly here: https://psalm.dev/r/31d5cccec3
I found these snippets:
https://psalm.dev/r/31d5cccec3
<?php
class Bar {
/** @var array{0: string, 1:string} */
private $baz = ["a", "b"];
/**
* @param 0|1 $index
*/
public function append(string $str, int $index) : void {
$this->baz[$index] = $str;
}
}
Psalm output (using commit 887a635):
ERROR: PropertyTypeCoercion - 11:4 - $this->baz expects 'array{0: string, 1: string}', parent type 'non-empty-array<int(0)|int(1), string>' provided
that different bug was fixed int c77f2cd
waits for psalm.dev to update
@muglug https://psalm.dev/r/31d5cccec3 still appears to be bugged in c77f2cd ?
I found these snippets:
https://psalm.dev/r/31d5cccec3
<?php
class Bar {
/** @var array{0: string, 1:string} */
private $baz = ["a", "b"];
/**
* @param 0|1 $index
*/
public function append(string $str, int $index) : void {
$this->baz[$index] = $str;
}
}
Psalm output (using commit c77f2cd):
ERROR: PropertyTypeCoercion - 11:4 - $this->baz expects 'array{0: string, 1: string}', parent type 'non-empty-array<int(0)|int(1), string>' provided