1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix byref array assignment

Fixes #1702
This commit is contained in:
Matthew Brown 2019-06-08 10:32:40 -04:00
parent d44be5eb9c
commit c38108f95d
2 changed files with 37 additions and 0 deletions

View File

@ -119,6 +119,25 @@ class ArrayAnalyzer
return false;
}
if ($item->byRef) {
$var_id = ExpressionAnalyzer::getArrayVarId(
$item->value,
$statements_analyzer->getFQCLN(),
$statements_analyzer
);
if ($var_id) {
$context->removeDescendents(
$var_id,
$context->vars_in_scope[$var_id],
null,
$statements_analyzer
);
$context->vars_in_scope[$var_id] = Type::getMixed();
}
}
if ($item_value_atomic_types && !$can_create_objectlike) {
continue;
}

View File

@ -502,6 +502,24 @@ class ArrayAccessTest extends TestCase
[],
['MixedReturnStatement', 'MixedInferredReturnType']
],
'arrayAccessAfterByRefArrayOffsetAssignment' => [
'<?php
/**
* @param array{param1: array} $params
*/
function dispatch(array $params) : void {
$params["param1"]["foo"] = "bar";
}
$ar = [];
dispatch(["param1" => &$ar]);
$value = "foo";
if (isset($ar[$value])) {
echo (string) $ar[$value];
}',
[],
['MixedArrayAccess'],
],
];
}