diff --git a/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php b/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php index 494f6aa24..07b74dab5 100644 --- a/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php +++ b/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php @@ -297,17 +297,26 @@ class AssignmentChecker if ($var instanceof PhpParser\Node\Expr\List_ || $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( $statements_checker, $var, null, - Type::getMixed(), + $array_value_type ? clone $array_value_type->type_params[1] : Type::getMixed(), $context, $doc_comment ); } - $list_var_id = ExpressionChecker::getVarId( + $list_var_id = ExpressionChecker::getArrayVarId( $var, $statements_checker->getFQCLN(), $statements_checker diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index 6288b2f2e..3c6ff3cb9 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -109,6 +109,12 @@ class ArrayAccessTest extends TestCase $len = strlen($key); }', ], + 'listAssignmentKeyOffset' => [ + '