1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix handling of built arrays

This commit is contained in:
Brown 2020-04-08 16:11:11 -04:00
parent 43287812ce
commit d868710b2b
4 changed files with 28 additions and 2 deletions

View File

@ -121,7 +121,6 @@ class Creator
$issues_at_level[$issue_level][$issue_type] = 0;
}
/** @psalm-suppress MixedOperand */
$issues_at_level[$issue_level][$issue_type] += 100/$counted_types;
}

View File

@ -118,7 +118,7 @@ class ArrayFetchAnalyzer
if ($keyed_array_var_id
&& $context->hasVariable($keyed_array_var_id)
&& !$context->vars_in_scope[$keyed_array_var_id]->possibly_undefined
&& !$context->vars_in_scope[$keyed_array_var_id]->isVanillaMixed()
&& !$context->vars_in_scope[$keyed_array_var_id]->hasVanillaMixed()
) {
$statements_analyzer->node_data->setType(
$stmt,

View File

@ -978,6 +978,19 @@ class Union implements TypeNode
&& count($this->types) === 1;
}
/**
* @return bool
*/
public function hasVanillaMixed()
{
/**
* @psalm-suppress UndefinedPropertyFetch
*/
return isset($this->types['mixed'])
&& !$this->types['mixed']->from_loop_isset
&& get_class($this->types['mixed']) === Type\Atomic\TMixed::class;
}
/**
* @return bool
*/

View File

@ -985,6 +985,20 @@ class ForeachTest extends \Psalm\Tests\TestCase
$list = [4, 5, 6];
}',
],
'createNestedArrayInLoop' => [
'<?php
function foo() : void {
$arr = [];
foreach ([1, 2, 3] as $i) {
if (!isset($arr[$i]["a"])) {
$arr[$i]["a"] = 0;
}
$arr[$i]["a"] += 5;
}
}'
],
];
}