1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Uses by ref should be assigned that way

This commit is contained in:
Matt Brown 2020-11-13 12:50:01 -05:00
parent 4c1cf37d52
commit 57125c7106
2 changed files with 23 additions and 0 deletions

View File

@ -160,6 +160,10 @@ class ClosureAnalyzer extends FunctionLikeAnalyzer
? clone $context->vars_in_scope[$use_var_id]
: Type::getMixed();
if ($use->byRef) {
$use_context->vars_in_scope[$use_var_id]->by_ref = true;
}
$use_context->vars_possibly_in_scope[$use_var_id] = true;
foreach ($context->vars_in_scope as $var_id => $type) {

View File

@ -2236,6 +2236,25 @@ class UnusedVariableTest extends TestCase
return $b;
}'
],
'allowUseByRef' => [
'<?php
/**
* @psalm-suppress MixedReturnStatement
* @psalm-suppress MixedInferredReturnType
*/
function foo(array $data) : array {
$output = [];
array_map(
function (array $row) use (&$output) {
$output = $row;
},
$data
);
return $output;
}'
],
];
}