vimeo/psalm

Calling to `Map::union/intersect/diff()` etc. modifies args generic type

Open

#6,381 创建于 2021年8月31日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)PHP (668 fork)batch import
Help wantedbugtype reconciliation

仓库指标

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

描述

interface A {
    /**
     * @param TReturn $value
     *
     * @return Map<TReturn, TReturn>
     *
     * @template TReturn
     */
    public static function fc(mixed $value) : Map
    {
    }
}

/** @var A $a */
$a;

$result = $a::fc(true);

Type of $result is correctly Ds\Map<true, true>.

Though, when I route $result through any mutation-free function on another map instance ((new Map)->union($result)), it changes to Ds\Map<mixed, mixed>. I don't see any reason for type change.

https://psalm.dev/r/4243e3b2a8
https://psalm.dev/r/123220a2c8

贡献者指南