Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected MixedReturnStatement #10879

Open
dimajolkin opened this issue Apr 4, 2024 · 1 comment
Open

Unexpected MixedReturnStatement #10879

dimajolkin opened this issue Apr 4, 2024 · 1 comment

Comments

@dimajolkin
Copy link

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

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant