psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Unexpected MixedReturnStatement

Open dimajolkin opened this issue 10 months ago • 1 comments

Example psalm: https://psalm.dev/r/7a1ebb5700

Example phpstam: https://phpstan.org/r/1f5ed47d-410c-4b4e-9c5c-d0506dfb5ec8

dimajolkin avatar Apr 04 '24 07:04 dimajolkin

I found these snippets:

https://psalm.dev/r/7a1ebb5700
<?php
/**
*
* @template TValue
* @template TResultValue
* 
* @param callable(TValue):TResultValue $func
* @param iterable<TValue> $list
*
* @return list<TResultValue>
*/
function list_map(callable $func, iterable $list): iterable
{
    $result = [];
    foreach($list as $item) {
        $result[] = $func($item);
    }
    
    return $result;
}


$data = [['name' => 'string']];

$result = list_map(fn (array $value): string => $value['name'], $data);


var_export($result);
Psalm output (using commit ef3b018):

INFO: PossiblyUndefinedStringArrayOffset - 25:49 - Possibly undefined array offset ''name'' is risky given expected type 'array-key'. Consider using isset beforehand.

INFO: MixedReturnStatement - 25:49 - Could not infer a return type

psalm-github-bot[bot] avatar Apr 04 '24 07:04 psalm-github-bot[bot]