Skip to content

Wrong type for iterable param with phpdoc type array<int, Token>|Tokens #13411

@gharlan

Description

@gharlan

Bug report

<?php declare(strict_types = 1);

class Token {}

/** @extends SplFixedArray<Token> */
class Tokens extends SplFixedArray {}

/** @param array<int, Token>|Tokens $tokens */
function x(iterable $tokens): int {
	return count($tokens);
}

PHPStan resolves the type of $tokens inside x to iterable<int, Token>|Tokens. But it should be array<int, Token>|Tokens, as noted in phpdocs.
I cannot use native array|Tokens union type for bc reasons and for compatibility to php 7.4 (real code is here).

Code snippet that reproduces the problem

https://phpstan.org/r/dc5f61e0-0c94-4e1b-a61b-971794274b95

Expected output

No errors.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions