Skip to content

Adding element to array/list should promote it to non-empty #4016

@b1rdex

Description

@b1rdex

https://phpstan.org/r/25383d75-a004-43d6-83cf-df864f99c806

<?php declare(strict_types = 1);

/** @param non-empty-list<mixed> $foo */
function sayHello($foo): void
{
}

/** @return list<int> */
function getList(): array {
	return [];
}

$a = getList();
$a[] = 1;
sayHello($a);

I'm not sure if it's possible in the current PHPStan... Just wondering. It'd be great to detect this.

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