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

Fix #6061 — delay analysis of array value except when unpacking (#6081)

This commit is contained in:
Matthew Brown 2021-07-12 17:05:33 -04:00 committed by GitHub
parent e93b37a225
commit f2bc6913db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -232,11 +232,11 @@ class ArrayAnalyzer
PhpParser\Node\Expr\ArrayItem $item,
Codebase $codebase
) : void {
if (ExpressionAnalyzer::analyze($statements_analyzer, $item->value, $context) === false) {
return;
}
if ($item->unpack) {
if (ExpressionAnalyzer::analyze($statements_analyzer, $item->value, $context) === false) {
return;
}
$unpacked_array_type = $statements_analyzer->node_data->getType($item->value);
if (!$unpacked_array_type) {
@ -335,6 +335,10 @@ class ArrayAnalyzer
$array_creation_info->item_key_atomic_types[] = new Type\Atomic\TLiteralInt($item_key_value);
}
if (ExpressionAnalyzer::analyze($statements_analyzer, $item->value, $context) === false) {
return;
}
$array_creation_info->all_list = $array_creation_info->all_list && $item_is_list_item;
if ($item_key_value !== null) {

View File

@ -2392,6 +2392,16 @@ class UnusedVariableTest extends TestCase
return implode("/", $arr);
}'
],
'initVariableInOffset' => [
'<?php
$a = [
$b = "b" => $b,
];
foreach ($a as $key => $value) {
echo $key . " " . $value;
}',
],
];
}