mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Allow empty arrays to change type after block
This commit is contained in:
parent
ddd8f991a9
commit
00a6a54cf5
@ -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);
|
||||
}
|
||||
|
@ -395,6 +395,11 @@ abstract class Type
|
||||
}
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->value === 'empty';
|
||||
}
|
||||
|
||||
public function isObject()
|
||||
{
|
||||
if ($this instanceof Atomic) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user