vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 660 forks source link

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

Open weirdan opened 5 months ago

weirdan commented 5 months ago

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

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

psalm-github-bot[bot] commented 5 months ago

I found these snippets:

https://psalm.dev/r/3a4e97147a ```php */ 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 */ 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 ```