1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1873 - allow spread operators in inferred property types

This commit is contained in:
Matthew Brown 2019-06-28 22:28:35 -04:00
parent cba187ad56
commit cb28c44228
2 changed files with 28 additions and 1 deletions

View File

@ -1870,7 +1870,23 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
continue;
}
$assigned_properties[$property_name] = $storage->param_types[$param_name];
$param_index = \array_search($param_name, \array_keys($storage->param_types));
if (!isset($storage->params[$param_index]->type)) {
continue;
}
$param_type = $storage->params[$param_index]->type;
$assigned_properties[$property_name] =
$storage->params[$param_index]->is_variadic
? new Type\Union([
new Type\Atomic\TArray([
Type::getInt(),
$param_type
])
])
: $param_type;
} else {
$assigned_properties = [];
break;

View File

@ -1651,6 +1651,17 @@ class PropertyTypeTest extends TestCase
}
}'
],
'inferSpreadParamType' => [
'<?php
class Tag {}
class EntityTags {
private $tags;
public function __construct(Tag ...$tags) {
$this->tags = $tags;
}
}'
],
];
}