Skip to content

Commit 5765cb4

Browse files
committed
Consider list-shape when interpreting array_shapes
1 parent 5534aea commit 5765cb4

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Diff for: src/PhpDoc/TypeNodeResolver.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,18 @@ function (CallableTypeParameterNode $parameterNode) use ($nameScope, &$isVariadi
10421042

10431043
private function resolveArrayShapeNode(ArrayShapeNode $typeNode, NameScope $nameScope): Type
10441044
{
1045+
$isListShape = in_array($typeNode->kind, [
1046+
ArrayShapeNode::KIND_LIST,
1047+
ArrayShapeNode::KIND_NON_EMPTY_LIST,
1048+
], true);
1049+
10451050
$builder = ConstantArrayTypeBuilder::createEmpty();
1046-
foreach ($typeNode->items as $itemNode) {
1047-
if ($itemNode->keyName !== null) {
1048-
$builder = ConstantArrayTypeBuilder::createEmptyIndeterminate();
1049-
break;
1051+
if (!$isListShape) {
1052+
foreach ($typeNode->items as $itemNode) {
1053+
if ($itemNode->keyName !== null) {
1054+
$builder = ConstantArrayTypeBuilder::createEmptyIndeterminate();
1055+
break;
1056+
}
10501057
}
10511058
}
10521059

@@ -1069,10 +1076,7 @@ private function resolveArrayShapeNode(ArrayShapeNode $typeNode, NameScope $name
10691076
}
10701077

10711078
$arrayType = $builder->getArray();
1072-
if (in_array($typeNode->kind, [
1073-
ArrayShapeNode::KIND_LIST,
1074-
ArrayShapeNode::KIND_NON_EMPTY_LIST,
1075-
], true)) {
1079+
if ($isListShape) {
10761080
$arrayType = TypeCombinator::intersect($arrayType, new AccessoryArrayListType());
10771081
}
10781082

0 commit comments

Comments
 (0)