1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Allow updating array by reference

This commit is contained in:
Brown 2020-06-15 14:44:55 -04:00
parent 8da80870e3
commit 8c5a434dc8
2 changed files with 24 additions and 0 deletions

View File

@ -1064,9 +1064,19 @@ class ArgumentsAnalyzer
}
if (!$arg->value instanceof PhpParser\Node\Expr\Variable) {
$suppressed_issues = $statements_analyzer->getSuppressedIssues();
if (!in_array('EmptyArrayAccess', $suppressed_issues, true)) {
$statements_analyzer->addSuppressedIssues(['EmptyArrayAccess']);
}
if (ExpressionAnalyzer::analyze($statements_analyzer, $arg->value, $context) === false) {
return false;
}
if (!in_array('EmptyArrayAccess', $suppressed_issues, true)) {
$statements_analyzer->removeSuppressedIssues(['EmptyArrayAccess']);
}
}
}
}

View File

@ -143,6 +143,20 @@ class ReferenceConstraintTest extends TestCase
function bar(I &$i) : void {}',
],
'notEmptyArrayAccess' => [
'<?php
/**
* @param mixed $value
* @param-out int $value
*/
function addValue(&$value) : void {
$value = 5;
}
$foo = [];
addValue($foo["a"]);'
],
];
}