Skip to content

Spreading a list into a new array results in a non-empty-list #5287

@MidnightDesign

Description

@MidnightDesign

Bug report

Code snippet that reproduces the problem

/**
 * @param list<mixed> $arr
 * @return list<mixed>|null
 */
function nullArray(array $arr): ?array {
    $copy = [...$arr];
    if (count($copy) === 0) {
        return null;
    }
    return $copy;
}

https://phpstan.org/r/83a4e3c7-d7b1-44c3-bf5d-7222a175ff1e
(The code doesn't make any sense. It's just there to prove there's a false positive.)

Expected output

No errors. If the input $arr is an empty list, the resulting $copy will be empty as well.

Actual output

Strict comparison using === between int<1, max> and 0 will always evaluate to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions