Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false positive with unpacked and named arguments #8500

Open
dstrop opened this issue Sep 21, 2022 · 2 comments
Open

false positive with unpacked and named arguments #8500

dstrop opened this issue Sep 21, 2022 · 2 comments
Labels

Comments

@dstrop
Copy link

dstrop commented Sep 21, 2022

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

@psalm-github-bot
Copy link

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

@orklah
Copy link
Collaborator

orklah commented Sep 22, 2022

It's possibly a flaw in the improvement I made here: #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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants