psalm icon indicating copy to clipboard operation
psalm copied to clipboard

[master] Generic implicit mixed parameter cannot be overriden by explicit mixed in the descendant

Open weirdan opened this issue 1 year ago • 1 comments

This is fine on 5.x, but it doesn't work on master:

https://psalm.dev/r/3a4e97147a

weirdan avatar Mar 23 '24 16:03 weirdan

I found these snippets:

https://psalm.dev/r/3a4e97147a
<?php

/** 
 * @template TK
 * @template TV
 */
abstract class Base1 {
    /**
     * @param TK $key
     * @param TV $value
     */
    public function f($key, $value): void {}
}

/** @extends Base1<int,int> */
class Descendant1 extends Base1 {
    public function f(mixed $key, mixed $value): void {
      /** @psalm-trace $key, $value */;
    }
}

// the only difference below is the explicit mixed type for Base2::f() params

/** 
 * @template TK
 * @template TV
 */
abstract class Base2 {
    /**
     * @param TK $key
     * @param TV $value
     */
    public function f(mixed $key, mixed $value): void {}
}

/** @extends Base2<int,int> */
class Descendant2 extends Base2 {
    public function f(mixed $key, mixed $value): void {
      /** @psalm-trace $key, $value */;
    }
}
Psalm output (using commit ef3b018):

INFO: Trace - 18:39 - $key: mixed

INFO: Trace - 18:39 - $value: mixed

INFO: Trace - 39:39 - $key: int

INFO: Trace - 39:39 - $value: int

psalm-github-bot[bot] avatar Mar 23 '24 16:03 psalm-github-bot[bot]