psalm icon indicating copy to clipboard operation
psalm copied to clipboard

false positive with unpacked and named arguments

Open dstrop opened this issue 2 years ago • 2 comments

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

dstrop avatar Sep 21 '22 18:09 dstrop

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

psalm-github-bot[bot] avatar Sep 21 '22 18:09 psalm-github-bot[bot]

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

orklah avatar Sep 22 '22 18:09 orklah