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

Variadic parameters and non-empty-list #5421

Closed
vjik opened this issue Mar 18, 2021 · 3 comments
Closed

Variadic parameters and non-empty-list #5421

vjik opened this issue Mar 18, 2021 · 3 comments
Labels

Comments

@vjik
Copy link
Contributor

vjik commented Mar 18, 2021

https://psalm.dev/r/7f75a28f23

In this example $x can be empty, but psalm understand this as non-empty-list. It is bug.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7f75a28f23
<?php

$x = [];
$y = [];

$x = [...$x, ...$y];

/** @psalm-trace $x */
$x ? 1 : 0;
Psalm output (using commit d19088b):

ERROR: RedundantCondition - 9:1 - Type non-empty-list<empty> for $x is never falsy

ERROR: TypeDoesNotContainType - 9:10 - Type non-empty-list<empty> for $x is never falsy

INFO: Trace - 9:1 - $x: non-empty-list<empty>

@weirdan weirdan added the bug label Mar 18, 2021
@AndrolGenhald
Copy link
Collaborator

I'm seeing several other issues creating arrays with the spread operator, here's a false negative: https://psalm.dev/r/e7aeb5831c
Should be like this: https://psalm.dev/r/2ac2479ad5

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/e7aeb5831c
<?php

/** @return array<array-key, int> */
function getArray(): array {
    return ['test' => 0];
}

function test(): array {
    $a = getArray();
    $b = [...$a];
    return $b;
}
Psalm output (using commit 42d3bce):

No issues!
https://psalm.dev/r/2ac2479ad5
<?php

/** @return array<string, int> */
function getArray(): array {
    return ['test' => 0];
}

function test(): array {
    $a = getArray();
    $b = [...$a];
    return $b;
}
Psalm output (using commit 42d3bce):

ERROR: DuplicateArrayKey - 10:14 - String keys are not supported in unpacked arrays

AndrolGenhald added a commit to AndrolGenhald/psalm that referenced this issue Mar 19, 2021
AndrolGenhald added a commit to AndrolGenhald/psalm that referenced this issue Mar 20, 2021
@muglug muglug closed this as completed in 0579c11 Mar 20, 2021
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