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:
parent
cba187ad56
commit
cb28c44228
@ -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;
|
||||
|
@ -1651,6 +1651,17 @@ class PropertyTypeTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'inferSpreadParamType' => [
|
||||
'<?php
|
||||
class Tag {}
|
||||
class EntityTags {
|
||||
private $tags;
|
||||
|
||||
public function __construct(Tag ...$tags) {
|
||||
$this->tags = $tags;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user