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

Treat array_push($a, ... as $a[]= ...

This commit is contained in:
Brown 2020-07-10 10:20:02 -04:00
parent d1ca68e57a
commit 38fdf4bef6

View File

@ -3,6 +3,7 @@ namespace Psalm\Internal\Analyzer\Statements\Expression\Call;
use PhpParser;
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\Assignment\ArrayAssignmentAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\AssignmentAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\ExpressionIdentifier;
@ -134,6 +135,38 @@ class ArrayFunctionArgumentsAnalyzer
) {
$array_arg = $args[0]->value;
if ($is_push) {
for ($i = 1; $i < count($args); $i++) {
if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$args[$i]->value,
$context
) === false) {
return false;
}
$old_node_data = $statements_analyzer->node_data;
$statements_analyzer->node_data = clone $statements_analyzer->node_data;
ArrayAssignmentAnalyzer::analyze(
$statements_analyzer,
new PhpParser\Node\Expr\ArrayDimFetch(
$args[0]->value,
null,
$args[$i]->value->getAttributes()
),
$context,
$args[$i]->value,
$statements_analyzer->node_data->getType($args[$i]->value) ?: Type::getMixed()
);
$statements_analyzer->node_data = $old_node_data;
}
return;
}
$context->inside_call = true;
if (ExpressionAnalyzer::analyze(