mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Allow updating array by reference
This commit is contained in:
parent
8da80870e3
commit
8c5a434dc8
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"]);'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user