diff --git a/composer.lock b/composer.lock index d0f35f001b..180a263828 100644 --- a/composer.lock +++ b/composer.lock @@ -2294,12 +2294,12 @@ "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "e104033df04ecfdf99e1923d13a1478143bac5a1" + "reference": "c00d78fb6b29658347f9d37ebe104bffadf36299" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/e104033df04ecfdf99e1923d13a1478143bac5a1", - "reference": "e104033df04ecfdf99e1923d13a1478143bac5a1", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/c00d78fb6b29658347f9d37ebe104bffadf36299", + "reference": "c00d78fb6b29658347f9d37ebe104bffadf36299", "shasum": "" }, "require": { @@ -2307,7 +2307,7 @@ }, "require-dev": { "doctrine/annotations": "^2.0", - "nikic/php-parser": "^5.1", + "nikic/php-parser": "^5.3.0", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^2.0", @@ -2334,7 +2334,7 @@ "issues": "https://github.com/phpstan/phpdoc-parser/issues", "source": "https://github.com/phpstan/phpdoc-parser/tree/2.0.x" }, - "time": "2024-09-26T07:29:34+00:00" + "time": "2024-10-13T11:29:49+00:00" }, { "name": "psr/container", diff --git a/src/PhpDoc/TypeNodeResolver.php b/src/PhpDoc/TypeNodeResolver.php index 0ebf7bccd8..6444c533e1 100644 --- a/src/PhpDoc/TypeNodeResolver.php +++ b/src/PhpDoc/TypeNodeResolver.php @@ -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; } diff --git a/tests/PHPStan/Analyser/nsrt/array-shape-list-optional.php b/tests/PHPStan/Analyser/nsrt/array-shape-list-optional.php index 0eaa4471d2..f059d14c4d 100644 --- a/tests/PHPStan/Analyser/nsrt/array-shape-list-optional.php +++ b/tests/PHPStan/Analyser/nsrt/array-shape-list-optional.php @@ -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); }