In 4.6.1, following code does not produce issues:
<?php
/**
* @psalm-assert iterable<string> $value
* @param mixed $value
*
* @return void
*/
function AssertAllString($value) : void
{
throw new \Exception(\var_export($value, true)); // irrelevant
}
/**
* @param ArrayIterator<string, mixed> $value
*
* @return ArrayIterator<string, string>
*/
function preserveContainerAllArrayIterator($value)
{
AssertAllString($value);
return $value;
}
In 4.6.2, the type is no longer refined:
Psalm output (using commit 594ef4f):
INFO: MixedReturnTypeCoercion - 23:12 - The type 'ArrayIterator<string, mixed>' is more general than the declared return type 'ArrayIterator<string, string>' for preserveContainerAllArrayIterator
INFO: MixedReturnTypeCoercion - 17:12 - The declared return type 'ArrayIterator<string, string>' for preserveContainerAllArrayIterator is more specific than the inferred return type 'ArrayIterator<string, mixed>'
Ref https://psalm.dev/r/90e3413397