From 1d10d8e8a219e01d24dad3fb17903bceca55120e Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 3 Oct 2016 01:01:24 -0400 Subject: [PATCH] Add hasType check --- src/Psalm/Checker/StatementsChecker.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index 3192bed01..13a1f8794 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -3920,20 +3920,22 @@ class StatementsChecker $array_type = $context_type; for ($i = 0; $i < $nesting + 1; $i++) { - if ($i < $nesting) { - if ($array_type->types['array']->type_params[1]->isEmpty()) { - $new_empty = clone $empty_type; + if ($array_type->hasArray()) { + if ($i < $nesting) { + if ($array_type->types['array']->type_params[1]->isEmpty()) { + $new_empty = clone $empty_type; - $new_empty->types['array']->type_params[0] = $key_type; + $new_empty->types['array']->type_params[0] = $key_type; - $array_type->types['array']->type_params[1] = $new_empty; - continue; + $array_type->types['array']->type_params[1] = $new_empty; + continue; + } + + $array_type = $array_type->types['array']->type_params[1]; + } + else { + $array_type->types['array']->type_params[0] = $key_type; } - - $array_type = $array_type->types['array']->type_params[1]; - } - elseif (isset($array_type->types['array'])) { - $array_type->types['array']->type_params[0] = $key_type; } }