bmewburn / vscode-intelephense

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

Inject parameter types into inline callable arguments - array_map #2823

Closed Indeedornot closed 3 months ago

Indeedornot commented 6 months ago

Describe the bug No type inference from array_map - As far as I know it has been introduced in 1.9 but does not work anymore

To Reproduce

        $test = array_map(fn($test) => $test, ['test']);

More complex example

    public function canAccessRoute(Route $route): bool
    {
        [$controller, $function] = explode('::', $route->getDefault('_controller'));
        $attrs = [...$this->reflection->findClassAttribute($controller, IsGranted::class)];
        $attrs = [...$attrs, ...$this->reflection->findClassAttribute($controller, IsGranted::class, $function)];
        if (empty($attrs)) {
            return true;
        }

        $isGranted = array_map(function (ReflectionAttribute $attr) {
            return $attr->getArguments()[0];
        }, $attrs);
        $isGranted = array_map(fn ($role) => $this->security->isGranted($role), $isGranted);
        return !in_array(false, $isGranted);
    }

Expected behavior Argument of an array_map closure is correctly infered and so is its transformation

Screenshots image image image image Looses generic type argument due to need for static typing to get hints

Platform and version Windows 10 Intelephense v1.10.2