Skip to content

Spread Operator in Array Expression should not always yield non-empty-array #6109

@bcremer

Description

@bcremer

Bug report

PHPStan will infer the result of using the Spread Operator in Array Expressions as non-empty-array but the result can still be an empty array.

Code snippet that reproduces the problem

/**
 * @return list<\stdClass>
 */
function returnMaybeEmptyList(): array
{
	return [];
}

PHPStan\dumpType(returnMaybeEmptyList()); // Dumped type: array<int, stdClass>

$options = [
    ...returnMaybeEmptyList(),
];

PHPStan\dumpType($options); // Dumped type: non-empty-array<int, stdClass>

https://phpstan.org/r/bb1162ce-c787-4ca6-b0dc-6d534e7bb632

Expected output

PHPStan\dumpType($options); // Dumped type: array<int, stdClass>

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