Skip to content

list<mixed> becomes array<int<0, max>, mixed> without array keys being modified #13809

@dontub

Description

@dontub

Bug report

If the values of a list are changed in a foreach where the key isn't part of the loop, the list isn't recognized as list anymore.

// $list becomes array<int<0, max>, mixed>
foreach ($list as &$value) {
	$value = 'foo';
}
// $list remains list<mixed>
foreach ($list as $key => &$value) {
	$value = 'foo';
}

Code snippet that reproduces the problem

https://phpstan.org/r/bd56bdd7-0fd4-423f-9086-7377e341204a

Expected output

Error is reported incorrectly.

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