psalm icon indicating copy to clipboard operation
psalm copied to clipboard

`MismatchingDocblockReturnType` with `iterable|object`

Open priyadi opened this issue 10 months ago • 1 comments

I believe this should not result in a MismatchingDocblockReturnType

https://psalm.dev/r/e367d0726c

/**
 * @template T
 */
interface FooInterface {
    /**
     * @return T|iterable<T>|null
     */
    public function foo(): object|array|null;
}

Using T|array<T>|\Traversable<T>|null also gives the same result.

priyadi avatar Apr 20 '24 14:04 priyadi

I found these snippets:

https://psalm.dev/r/e367d0726c
<?php

/**
 * @template T
 */
interface FooInterface {
    /**
     * @return T|iterable<T>|null
     */
    public function foo(): object|array|null;
}
Psalm output (using commit 08afc45):

ERROR: MismatchingDocblockReturnType - 8:16 - Docblock has incorrect return type '(T:FooInterface as mixed)|(iterable<mixed, T:FooInterface as mixed>)|null', should be 'array<array-key, mixed>|null|object'

psalm-github-bot[bot] avatar Apr 20 '24 14:04 psalm-github-bot[bot]