Skip to content

non-empty-list is now displayed as non-empty-array<int<0, max>, T> after upgrade from 2.1.29 to 2.1.32 #13851

@MartkCz

Description

@MartkCz

Bug report

Hi,

after upgrading PHPStan from 2.1.29 to 2.1.32, I noticed a change in how list types are displayed.

<?php declare(strict_types = 1);

use function PHPStan\dumpType;
use function PHPStan\Testing\assertType;

class Transaction {
	public function __construct(public int $value) {}

	public function withValue(int $value): self { return new self($value); }
}

/**
 * @return array<string, non-empty-list<Transaction>>
 */
function getPositions(): array
{
	return ['AAPL' => [new Transaction(50)], 'TSLA' => [new Transaction(50), new Transaction(100)]];
}

$positions = getPositions();

foreach ($positions as $symbol => &$transactions) {
	foreach ($transactions as &$transaction) {
		$transaction = $transaction->withValue(60);
	}
}

dumpType($positions);

Behavior in 2.1.29

The type was displayed as:

array<string, non-empty-list<Transaction>>

Behavior in 2.1.32

After upgrading to 2.1.32, it is displayed as:

array<string, non-empty-array<int<0, max>, Transaction>>

Code snippet that reproduces the problem

https://phpstan.org/r/4b38f403-d1d2-446a-b920-ddb0e45a096f

Expected output

array<string, non-empty-list>

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions