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

Destructuring array with skipped variables gives the wrong type hint #2846

Open
madrussa opened this issue Apr 8, 2024 · 0 comments
Open
Labels

Comments

@madrussa
Copy link

madrussa commented Apr 8, 2024

Describe the bug
When you have a tuple that returns an array of different types and it is hinted using the array-shape syntax. When you skip destructing values the next variable is typed incorrectly.

It seems to ignore the skipped values and starts matching the shape hints to the first destructured variable.

To Reproduce

<?php

class Test
{
    /**
     * @return array{0:int,1:string,2:array,3:bool}
     */
    public function getData(): array
    {
        return [100, '100', [], true];
    }

    public function test(): void
    {
        [,,$array, $bool] = $this->getData();
        // ^^^^^^ hinted as an integer

        list(,,$array, $bool) = $this->getData();
        //     ^^^^^^ hinted as an integer
    }
}

In the example above, Intelephense says that $array is an int and $bool is a string.

Expected behavior
Destructured variables are hinted properly, even when some are skipped.

Screenshots
Below should be hinted as an array:
image
image

Below should be hinted as a boolean:
image

Below shows hinting working properly when all values are destructured into variables:
image

Platform and version
MacOS: 14.3 (23D56)
Intelephense: v1.10.4

@bmewburn bmewburn added the bug label Apr 8, 2024
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

2 participants