diff --git a/src/Analyser/TypeSpecifier.php b/src/Analyser/TypeSpecifier.php index 1d8ca2608a9..78181834ae0 100644 --- a/src/Analyser/TypeSpecifier.php +++ b/src/Analyser/TypeSpecifier.php @@ -1274,11 +1274,16 @@ private function specifyTypesForCountFuncCall( $resultTypes = []; foreach ($type->getArrays() as $arrayType) { $isSizeSuperTypeOfArraySize = $sizeType->isSuperTypeOf($arrayType->getArraySize()); - if ($isSizeSuperTypeOfArraySize->no()) { + + if ($context->falsey()) { + if ($isSizeSuperTypeOfArraySize->yes()) { + continue; + } + $resultTypes[] = $arrayType; continue; } - if ($context->falsey() && $isSizeSuperTypeOfArraySize->maybe()) { + if ($isSizeSuperTypeOfArraySize->no()) { continue; } @@ -1371,6 +1376,13 @@ private function specifyTypesForCountFuncCall( $resultTypes[] = TypeCombinator::intersect($arrayType, new NonEmptyArrayType()); } + if ($context->falsey()) { + if (count($resultTypes) === 0) { + return null; + } + return $this->create($countFuncCall->getArgs()[0]->value, TypeCombinator::union(...$resultTypes), TypeSpecifierContext::createTrue(), $scope)->setRootExpr($rootExpr); + } + return $this->create($countFuncCall->getArgs()[0]->value, TypeCombinator::union(...$resultTypes), $context, $scope)->setRootExpr($rootExpr); } diff --git a/tests/PHPStan/Analyser/nsrt/bug-11488.php b/tests/PHPStan/Analyser/nsrt/bug-11488.php new file mode 100644 index 00000000000..dd7c35c38f6 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-11488.php @@ -0,0 +1,24 @@ +