vscode-intelephense
vscode-intelephense copied to clipboard
Template variables for iterable parameters not being inferred from Iterator or IteratorAggregate arguments
Describe the bug
Template variables are not being correctly inferred when passing an Iterator<T>
or IteratorAggregate<T>
into an iterable<T>
parameter.
To Reproduce
Create the following function:
/**
* @template T
*
* @param iterable<T> $testInput
*
* @return T
*/
function templateTest(iterable $testInput): mixed
{
return 'some value (pretend this is the correct type)';
}
And call this function with a variable of type Iterator
or IteratorAggregate
(ignore the actual value of the variable, it doesn't matter):
/** @var Iterator<string> */
$testInput = [];
$testOutput = templateTest($testInput);
/** @var IteratorAggregate<string> */
$testInput = [];
$testOutput = templateTest($testInput);
When you inspect the type of $testOutput
it will be mixed
.
Expected behavior
I expect the type of $testOutput
to be correctly inferred from the input type (in the above examples it should be string
).
This already works when passing an input value of type iterable
or array
:
/** @var iterable<string> */
$testInput = [];
$testOutput = templateTest($testInput);
/** @var array<string> */
$testInput = [];
$testOutput = templateTest($testInput);
In the above cases, the type of $testOutput
is correctly inferred as string
.
Screenshots
Platform and version
M2 Pro - macOS Sonoma 14.6 PHP Intelephense v1.12.6