diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index 88009646e43..456fd602dbb 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -10,10 +10,11 @@ use PHPStan\Analyser\TypeSpecifierContext; use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\Accessory\NonEmptyArrayType; +use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\FunctionTypeSpecifyingExtension; -use PHPStan\Type\TypeCombinator; use PHPStan\Type\TypeUtils; +use PHPStan\Type\UnionType; use function count; use function strtolower; @@ -47,12 +48,14 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n $arrayValueType = $arrayType->getIterableValueType(); $specifiedTypes = new SpecifiedTypes([], []); - if ($context->true() && $arrayType->isArray()->yes() && !$arrayType->isIterableAtLeastOnce()->yes()) { - $arrayType = TypeCombinator::intersect($arrayType, new NonEmptyArrayType()); - + if ($context->true() + && $arrayType->isArray()->yes() + && !$arrayType->isIterableAtLeastOnce()->yes() + && !($arrayType instanceof ConstantArrayType && $arrayType->isEmpty()) + && !$arrayType instanceof UnionType) { $specifiedTypes = $specifiedTypes->unionWith($this->typeSpecifier->create( $node->getArgs()[1]->value, - $arrayType, + new NonEmptyArrayType(), $context, false, $scope,