vimeo / psalm

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

wrong DocblockTypeContradiction #9106

Open timglabisch opened 1 year ago

timglabisch commented 1 year ago

Hello,

i am wondering why i get a DocblockTypeContradiction here: https://psalm.dev/r/7d6e377e13

phpstan likes the code: https://phpstan.org/r/33a08138-d052-4993-8203-cbb410eb329a

psalm-github-bot[bot] commented 1 year ago

I found these snippets:

https://psalm.dev/r/7d6e377e13 ```php |PItem */ class PermissionWrap { /** @var T */ private mixed $wrapped; /** @var P */ private $permissions; /** * @param T $wrapped * @param P $permissions */ public function __construct(mixed $wrapped, array|bool|object $permissions) { $this->wrapped = $wrapped; $this->permissions = $permissions; } /** * @param PItem $permission **/ public function isAllowed($permission = true): bool { if (is_bool($this->permissions)) { if (!is_bool($permission)) { throw new \LogicException(); } return (bool)$permission === (bool)$this->permissions; } return in_array((array)$permission, (array)$this->permissions, true); } /** @return T */ public function getWrapped(): mixed { return $this->wrapped; } } $a = new PermissionWrap(new \DateTime(), true); $a->isAllowed(); ``` ``` Psalm output (using commit d1c2294): ERROR: DocblockTypeContradiction - 30:7 - Docblock-defined type P:PermissionWrap as (PItem:PermissionWrap as bool|object)|(array) for $this->permissions is never bool ERROR: DocblockTypeContradiction - 31:9 - Docblock-defined type PItem:PermissionWrap as bool|object for $permission is always bool ```
orklah commented 1 year ago

That's a bug indeed