vimeo/psalm

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

オープン

#6,381 opened on 2021/08/31

 (5 件のコメント) (0 件のリアクション) (0 人の担当者)PHP (668 件のフォーク)batch import
Help wantedbugtype reconciliation

Repository metrics

Stars
 (5,369 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド