vimeo/psalm

Psalm does not infer type in array_reduce()

Open

#6,370 创建于 2021年8月27日

在 GitHub 查看
 (6 评论) (1 反应) (0 负责人)PHP (668 fork)batch import
Help wantedenhancement

仓库指标

Star
 (5,369 star)
PR 合并指标
 (平均合并 3天 12小时) (30 天内合并 5 个 PR)

描述

Given the following code:

/**
 * @param array<array{tags: string}> $a
 */
function test(array $a): string
{
    return array_reduce($a, function (string $carry, array $value) {
        return $carry . $value['tags'];
    }, '');
}

Psalm is unable to infer a type for $value in the callback function given to array_reduce():

https://psalm.dev/r/b9e02bcaaa

In this example, it should infer the type as array{tags: string}.

Can this be fixed?

贡献者指南