mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Allow list vars to have array keys
This commit is contained in:
parent
be72423980
commit
9404de699d
@ -297,17 +297,26 @@ class AssignmentChecker
|
|||||||
if ($var instanceof PhpParser\Node\Expr\List_
|
if ($var instanceof PhpParser\Node\Expr\List_
|
||||||
|| $var instanceof PhpParser\Node\Expr\Array_
|
|| $var instanceof PhpParser\Node\Expr\Array_
|
||||||
) {
|
) {
|
||||||
|
/** @var Type\Atomic\ObjectLike|Type\Atomic\TArray|null */
|
||||||
|
$array_value_type = isset($assign_value_type->getTypes()['array'])
|
||||||
|
? $assign_value_type->getTypes()['array']
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if ($array_value_type instanceof Type\Atomic\ObjectLike) {
|
||||||
|
$array_value_type = $array_value_type->getGenericArrayType();
|
||||||
|
}
|
||||||
|
|
||||||
self::analyze(
|
self::analyze(
|
||||||
$statements_checker,
|
$statements_checker,
|
||||||
$var,
|
$var,
|
||||||
null,
|
null,
|
||||||
Type::getMixed(),
|
$array_value_type ? clone $array_value_type->type_params[1] : Type::getMixed(),
|
||||||
$context,
|
$context,
|
||||||
$doc_comment
|
$doc_comment
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$list_var_id = ExpressionChecker::getVarId(
|
$list_var_id = ExpressionChecker::getArrayVarId(
|
||||||
$var,
|
$var,
|
||||||
$statements_checker->getFQCLN(),
|
$statements_checker->getFQCLN(),
|
||||||
$statements_checker
|
$statements_checker
|
||||||
|
@ -109,6 +109,12 @@ class ArrayAccessTest extends TestCase
|
|||||||
$len = strlen($key);
|
$len = strlen($key);
|
||||||
}',
|
}',
|
||||||
],
|
],
|
||||||
|
'listAssignmentKeyOffset' => [
|
||||||
|
'<?php
|
||||||
|
$a = [];
|
||||||
|
list($a["foo"]) = explode("+", "a+b");
|
||||||
|
echo $a["foo"];',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user