Skip to content

non-empty-array&hasOffset has unexpected type compatiiblity #13964

@erikgaal

Description

@erikgaal

Bug report

From a project I'm working on, tried to make it as simple as possible.

/** @var array<string, array<mixed>> $state */
$state = (fn()=>[])();

$state = array_map(function (array $item): array {
	if (array_key_exists('type', $item) && array_key_exists('data', $item)) {
		return $item;
	}

	return [
		'type' => 'type',
		'data' => $item,
	];
}, $state);

This is giving an error during analysis:

Anonymous function should return non-empty-array but returns non-empty-array.

I don't think this should report this error, or at the very least the error should be more descriptive...

Dumping the type of the item that's being returned gives me non-empty-array&hasOffset('data')&hasOffset('type') so it might have something to do with non-empty-array not accepting non-empty-array&hasOffset?

Code snippet that reproduces the problem

https://phpstan.org/r/4010febf-b2ab-481c-9812-a4bdd33440b1

Expected output

No error

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

I cannot imagine living without PHPStan anymore!

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