phpstan / phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
https://phpstan.org/
MIT License
12.86k stars 871 forks source link

duplicate param typehints unexpectedly result in no typehint detected #1931

Open SignpostMarv opened 5 years ago

SignpostMarv commented 5 years ago

checked w/ phpstan 0.11.2 & phpstan.org

Summary of a problem or a feature request

Accidentally added a duplicate & conflicting param hint to a method & rather than flagging up a duplicate typehint, phpstan reports no typehint detected.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

/**
* @param mixed $val
*
* @param scalar|array|object|null $val
*/
function foo($val) : void {
    echo var_export($val, true);
}

+----------------------------------------------------------------------+ | Line | test.php | +----------------------------------------------------------------------+ | 8 | Function foo() has parameter $val with no typehint specified. | +----------------------------------------------------------------------+

Expected output

Expecting phpstan to report that function foo() has duplicate typehints- it'd be nice if the typehints were also reported as being conflicting (as opposed to identical-after-normalisation), but that's not essential.

adaamz commented 5 years ago

At least it took your attention! 😄

phpstan-bot commented 3 years ago

@SignpostMarv PHPStan now reports different result with your code snippet:

@@ @@
-8: Function foo() has parameter $val with no typehint specified.
+8: Function foo() has parameter $val with no value type specified in iterable type array.
Full report | Line | Error | |---|---| | 8 | `Function foo() has parameter $val with no value type specified in iterable type array.` |