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

Array spread operator false negative #5431

Closed
AndrolGenhald opened this issue Mar 19, 2021 · 3 comments
Closed

Array spread operator false negative #5431

AndrolGenhald opened this issue Mar 19, 2021 · 3 comments

Comments

@AndrolGenhald
Copy link
Collaborator

Caused by fix to #2852. It might be slightly annoying to have to annotate with list<mixed> or array<int, mixed> instead of just function test(): array {}, but this is definitely a false negative considering that this code crashes: https://psalm.dev/r/ef5d2a6084 https://3v4l.org/9q0Eq

@psalm-github-bot
Copy link

I found these snippets:

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

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

function test(): array {
    $a = getArray();
    $b = [...$a];
    return $b;
}

test();
Psalm output (using commit 42d3bce):

No issues!

@weirdan
Copy link
Collaborator

weirdan commented Mar 19, 2021

Note that spread with string keys will become valid in 8.1: https://3v4l.org/DSLic/rfc#git.master, https://wiki.php.net/rfc/array_unpacking_string_keys

@AndrolGenhald
Copy link
Collaborator Author

Note that spread with string keys will become valid in 8.1

Cool! Maybe I'll work on adding support sometime since I've already familiarized myself with ArrayAnalyzer.

@muglug muglug closed this as completed in b859fba Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants