Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.12.x' into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 13, 2024
2 parents 2de40d1 + 107a7e3 commit b3cd815
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,10 +1015,20 @@ private function resolveArrayShapeNode(ArrayShapeNode $typeNode, NameScope $name
}

$arrayType = $builder->getArray();
if ($typeNode->kind === ArrayShapeNode::KIND_LIST) {
if (in_array($typeNode->kind, [
ArrayShapeNode::KIND_LIST,
ArrayShapeNode::KIND_NON_EMPTY_LIST,
], true)) {
$arrayType = TypeCombinator::intersect($arrayType, new AccessoryArrayListType());
}

if (in_array($typeNode->kind, [
ArrayShapeNode::KIND_NON_EMPTY_ARRAY,
ArrayShapeNode::KIND_NON_EMPTY_LIST,
], true)) {
$arrayType = TypeCombinator::intersect($arrayType, new NonEmptyArrayType());
}

return $arrayType;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/nsrt/array-shape-list-optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ class Foo

/**
* @param list{0: string, 1: int, 2?: string, 3?: string} $valid1
* @param non-empty-list{0: string, 1: int, 2?: string, 3?: string} $valid2
* @param non-empty-array{0?: string, 1?: int, 2?: string, 3?: string} $valid3
* @param list{0: string, 1: int, 2?: string, 4?: string} $invalid1
* @param list{0: string, 1: int, 2?: string, foo?: string} $invalid2
*/
public function doFoo(
$valid1,
$valid2,
$valid3,
$invalid1,
$invalid2
): void
{
assertType('array{0: string, 1: int, 2?: string, 3?: string}&list', $valid1);
assertType('array{0: string, 1: int, 2?: string, 3?: string}&list', $valid2);
assertType('array{0?: string, 1?: int, 2?: string, 3?: string}&non-empty-array', $valid3);
assertType('*NEVER*', $invalid1);
assertType('*NEVER*', $invalid2);
}
Expand Down

0 comments on commit b3cd815

Please sign in to comment.