diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index f75680601..71b63aa24 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -2211,6 +2211,16 @@ class StatementsChecker return null; } + public static function getArrayVarId(PhpParser\Node\Expr $stmt) + { + if ($stmt instanceof PhpParser\Node\Expr\ArrayDimFetch && $stmt->dim instanceof PhpParser\Node\Scalar\String_) { + $root_var_id = self::getArrayVarId($stmt->var); + return $root_var_id ? $root_var_id . '[\'' . $stmt->dim->value . '\']' : null; + } + + return self::getVarId($stmt); + } + protected function checkArrayAssignment(PhpParser\Node\Expr\ArrayDimFetch $stmt, Context $context, Type\Union $assignment_value_type) { if ($stmt->dim && $this->checkExpression($stmt->dim, $context, false) === false) { diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index ea1d34dae..6b7e57903 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -256,7 +256,7 @@ class TypeChecker } else if ($conditional->expr instanceof PhpParser\Node\Expr\Isset_) { foreach ($conditional->expr->vars as $isset_var) { - $var_name = StatementsChecker::getVarId($isset_var); + $var_name = StatementsChecker::getVarId($isset_var) ?: StatementsChecker::getArrayVarId($isset_var); if ($var_name) { $if_types[$var_name] = 'null'; } @@ -409,7 +409,7 @@ class TypeChecker } else if ($conditional instanceof PhpParser\Node\Expr\Isset_) { foreach ($conditional->vars as $isset_var) { - $var_name = StatementsChecker::getVarId($isset_var); + $var_name = StatementsChecker::getVarId($isset_var) ?: StatementsChecker::getArrayVarId($isset_var); if ($var_name) { $if_types[$var_name] = '!null'; }