1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Allow empty arrays to change type after block

This commit is contained in:
Matthew Brown 2016-07-12 01:28:41 -04:00
parent ddd8f991a9
commit 00a6a54cf5
2 changed files with 20 additions and 1 deletions

View File

@ -1601,7 +1601,6 @@ class StatementsChecker
}
} else if ($stmt->var instanceof PhpParser\Node\Expr\ArrayDimFetch) {
if ($this->_checkArrayAssignment($stmt->var, $context, $return_type) === false) {
return false;
}
@ -2604,6 +2603,21 @@ class StatementsChecker
$context->vars_in_scope = array_merge($context->vars_in_scope, $redefined_vars);
}
}
elseif ($redefined_vars) {
foreach ($redefined_vars as $var_name => $union_type) {
foreach ($union_type->types as $type) {
foreach ($context->vars_in_scope[$var_name]->types as $context_type) {
if ($context_type instanceof Type\Generic &&
$context_type instanceof Type\Generic &&
$context_type->type_params[0]->isEmpty()
) {
$context_type->type_params[0] = $type->type_params[0];
}
}
}
}
}
$context->vars_possibly_in_scope = array_merge($context->vars_possibly_in_scope, $new_vars_possibly_in_scope);
}

View File

@ -395,6 +395,11 @@ abstract class Type
}
}
public function isEmpty()
{
return $this->value === 'empty';
}
public function isObject()
{
if ($this instanceof Atomic) {