vimeo / psalm

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

Duplicated @param makes Psalm fail getting correct type #10466

Open rarila opened 10 months ago

rarila commented 10 months ago

I wonder if Psalm should just fail with that duplicated param and get the other one correct?!

https://psalm.dev/r/2a4bdb7173

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

I found these snippets:

https://psalm.dev/r/2a4bdb7173 ```php $array */ public function func(string $string, array $array): void; } class Works implements WorksInterface { public function func(string $string, array $array): void { /** @psalm-trace $array */ } } interface FailsInterface { /** * InvalidDocblock * @param string $string * @param string $string * @param array $array */ public function func(string $string, array $array): void; } class Fails implements FailsInterface { public function func(string $string, array $array): void { /** @psalm-trace $array */ } } ``` ``` Psalm output (using commit 0e43c44): ERROR: InvalidDocblock - 29:5 - Found duplicated @param or prefixed @param tag in docblock for FailsInterface::func INFO: Trace - 16:0 - $array: array INFO: Trace - 36:0 - $array: array ```
kkmuffme commented 10 months ago

That's expected - it reports InvalidDocblock - fix that error and you will have correct types.

In this case it's simple (bc they are identical), but what if the types were different?

rarila commented 10 months ago

@kkmuffme "fix that error"… sure, as long as it’s your code. But that can be in an upstream library and you you know that it sometimes can take time to get something fixed upstream ;-) (Btw, in my case here I got it fixed quite fast)

Anyway, the problem here isn’t that Psalm does not know what to do with the erroneous $string, but Psalm get’s $array wrong afterwards, that has correct doc. So IMHO even if types of $string would be different, Psalm should get the $array type correct.__