psalm
psalm copied to clipboard
false positive with unpacked and named arguments
when function is called with unpacked arguments and named arguments Psalm ignores the named arguments
https://psalm.dev/r/018f0616de
i expected no No issues!
but instead Psalm reported mixed type for second argument
even though if i supplied the second parameter through upacked arguments it would result in PHP Fatal error and Psalm detects
I found these snippets:
https://psalm.dev/r/018f0616de
<?php declare(strict_types = 1);
function add(int $a, int $b): int {
return $a + $b;
}
$args = ['a' => 7];
print add(...$args, b: 8);
Psalm output (using commit 028ac7f):
INFO: MixedArgument - 9:14 - Argument 2 of add cannot be mixed, expecting int
It's possibly a flaw in the improvement I made here: https://github.com/vimeo/psalm/pull/7348 or something very close
This is admittedly a pretty niche case, unpacking a sealed array then using a named parameter is a little weird, but as long as the array is sealed, it should be possible to adapt the code by both counting the elements in the array and deducting the named elements