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

Wrong implicit integer key inferred in static arrays #6289

Closed
weirdan opened this issue Aug 11, 2021 · 1 comment · Fixed by #6290
Closed

Wrong implicit integer key inferred in static arrays #6289

weirdan opened this issue Aug 11, 2021 · 1 comment · Fixed by #6290
Assignees
Labels

Comments

@weirdan
Copy link
Collaborator

weirdan commented Aug 11, 2021

https://psalm.dev/r/d7d194894c

Expected: key for the "aa" element should be inferred to be 6 (https://3v4l.org/TYqhH)
Actual: it's inferred to be 2

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/d7d194894c
<?php
class C {
    const A = [5 => "a", "zz" => "z", "aa"];
}
$arr = C::A;
/** @psalm-trace $arr */;
Psalm output (using commit 7c339c1):

INFO: Trace - 6:25 - $arr: array{2: "aa", 5: "a", zz: "z"}

INFO: UnusedVariable - 5:1 - $arr is never referenced or the value is not used

@weirdan weirdan self-assigned this Aug 11, 2021
weirdan added a commit to weirdan/psalm that referenced this issue Aug 11, 2021
This fixes int offset inference and adds handling for array unpacks in
constant arrays. Mostly it's copy/pasted from `ArrayAnalyzer` with
further adjustments.

Fixes vimeo#6263
Fixes vimeo#6289
weirdan added a commit to weirdan/psalm that referenced this issue Aug 12, 2021
This fixes int offset inference and adds handling for array unpacks in
constant arrays. Mostly it's copy/pasted from `ArrayAnalyzer` with
further adjustments.

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

Successfully merging a pull request may close this issue.

1 participant