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

Prevent creating empty objectlike

This commit is contained in:
Matthew Brown 2017-03-20 02:05:58 -04:00
parent 73b5eb1530
commit 066b1e011e
2 changed files with 18 additions and 3 deletions

View File

@ -950,9 +950,18 @@ class FetchChecker
? [$string_key_value => $keyed_assignment_type]
: [];
$assignment_type = new Type\Union([
new Type\Atomic\ObjectLike($properties)
]);
if ($properties) {
$assignment_type = new Type\Union([
new Type\Atomic\ObjectLike($properties)
]);
} else {
$assignment_type = new Type\Union([
new Type\Atomic\TArray([
$key_type,
$keyed_assignment_type
])
]);
}
} else {
if (!$keyed_assignment_type) {
throw new \UnexpectedValueException('$keyed_assignment_type cannot be null');

View File

@ -687,6 +687,12 @@ class ExpressionChecker
}
} else {
$item_value_type = Type::getMixed();
if ($item->key instanceof PhpParser\Node\Scalar\String_) {
$property_types[$item->key->value] = Type::getMixed();
} else {
$can_create_objectlike = false;
}
}
}