bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.57k stars 93 forks source link

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

Closed madrussa closed 1 week ago

madrussa commented 2 months ago

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