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

ArrayAnalyzer int_offset broken #5427

Closed
AndrolGenhald opened this issue Mar 18, 2021 · 4 comments
Closed

ArrayAnalyzer int_offset broken #5427

AndrolGenhald opened this issue Mar 18, 2021 · 4 comments

Comments

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Mar 18, 2021

For object-like arrays with some keys specified and some not $int_offset assigns the wrong key.
https://psalm.dev/r/1066dc35a8
It's out of order too (assuming object-like arrays are supposed to retain order). Edit: sorting properties on non-list keyed arrays seems to be intentional.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/1066dc35a8
<?php
$a = [1, 'a' => 2, 3];
/** @psalm-trace $a */ // $a is actually [0 => 1, 'a' => 2, 1 => 3];
Psalm output (using commit 42d3bce):

INFO: Trace - 3:69 - $a: array{0: 1, 2: 3, a: 2}

INFO: UnusedVariable - 2:1 - $a is never referenced or the value is not used

@AndrolGenhald
Copy link
Collaborator Author

Should this be allowed?
https://psalm.dev/r/a37bd3cac6
Technically valid, but seems weird.

@psalm-github-bot
Copy link

I found these snippets:

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

/** @return list<int> */
function returnList(): array {
    return [1, 1 => 2, 3];
}
Psalm output (using commit 42d3bce):

ERROR: InvalidReturnStatement - 5:12 - The inferred type 'array{0: 1, 1: 2, 2: 3}' does not match the declared return type 'list<int>' for returnList

ERROR: InvalidReturnType - 3:13 - The declared return type 'list<int>' for returnList is incorrect, got 'array{0: 1, 1: 2, 2: 3}'

AndrolGenhald added a commit to AndrolGenhald/psalm that referenced this issue Mar 18, 2021
@weirdan
Copy link
Collaborator

weirdan commented Mar 18, 2021

Technically valid, but seems weird.

Looks like a false-positive to me.

@muglug muglug closed this as completed in d459071 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