Skip to content
Permalink
Browse files

Properly clone array when changing value

  • Loading branch information...
muglug committed Aug 27, 2019
1 parent aba3659 commit 095ea1a554be19e3e20112a5c8426ebb418518a9
@@ -222,12 +222,12 @@ public static function updateArrayType(
$child_stmt->var->inferredType = clone $context->vars_in_scope[$parent_var_id];
}
$parent_var_id = $array_var_id;
$array_type = clone $child_stmt->var->inferredType;
$child_stmt->inferredType = ArrayFetchAnalyzer::getArrayAccessTypeGivenOffset(
$statements_analyzer,
$child_stmt,
$child_stmt->var->inferredType,
$array_type,
isset($child_stmt->dim->inferredType) ? $child_stmt->dim->inferredType : Type::getInt(),
true,
$array_var_id,
@@ -236,13 +236,28 @@ public static function updateArrayType(
$child_stmts ? null : $assignment_type
);
$child_stmt->var->inferredType = $array_type;
if ($root_var_id) {
if (!$parent_var_id) {
$rooted_parent_id = $root_var_id;
$root_type = $array_type;
} else {
$rooted_parent_id = $parent_var_id;
}
$context->vars_in_scope[$rooted_parent_id] = $array_type;
}
if (!$child_stmts) {
$child_stmt->inferredType = $assignment_type;
}
$current_type = $child_stmt->inferredType;
$current_dim = $child_stmt->dim;
$parent_var_id = $array_var_id;
if ($child_stmt->var->inferredType->hasMixed()) {
$full_var_id = false;
break;
@@ -765,7 +765,9 @@ private static function scrapeTypeProperties(
);
}
unset($possibly_undefined_entries[$candidate_property_name]);
if (!$type->had_mixed_value) {
unset($possibly_undefined_entries[$candidate_property_name]);
}
}
if ($combination->array_counts !== null) {
@@ -1086,6 +1086,20 @@ function bar(array $arr) : void {
foo($arr);
}'
],
'checkEmptinessAfterConditionalArrayAdjustment' => [
'<?php
class A {
public array $arr = [];
public function foo() : void {
if (rand(0, 1)) {
$this->arr["a"] = "hello";
}
if (!$this->arr) {}
}
}'
],
];
}

0 comments on commit 095ea1a

Please sign in to comment.
You can’t perform that action at this time.