diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 0f1e58c89f..4080ea69e1 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -746,17 +746,13 @@ public function getSpaceshipType(Expr $left, Expr $right, callable $getTypeCallb $leftTypesCount = count($leftTypes); $rightTypesCount = count($rightTypes); - if ($leftTypesCount > 0 && $rightTypesCount > 0) { + if ($leftTypesCount > 0 && $rightTypesCount > 0 && $leftTypesCount * $rightTypesCount <= self::CALCULATE_SCALARS_LIMIT) { $resultTypes = []; - $generalize = $leftTypesCount * $rightTypesCount > self::CALCULATE_SCALARS_LIMIT; foreach ($leftTypes as $leftType) { foreach ($rightTypes as $rightType) { $leftValue = $leftType->getValue(); $rightValue = $rightType->getValue(); $resultType = $this->getTypeFromValue($leftValue <=> $rightValue); - if ($generalize) { - $resultType = $resultType->generalize(GeneralizePrecision::lessSpecific()); - } $resultTypes[] = $resultType; } } diff --git a/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php index e34d62059b..3155b387c2 100644 --- a/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php @@ -60,4 +60,9 @@ public function testBug8179(): void $this->analyse([__DIR__ . '/data/bug-8179.php'], []); } + public function testBugSpaceship(): void + { + $this->analyse([__DIR__ . '/data/bug-spaceship.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-spaceship.php b/tests/PHPStan/Rules/Functions/data/bug-spaceship.php new file mode 100644 index 0000000000..3200b58dc7 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-spaceship.php @@ -0,0 +1,6 @@ + $a <=> $b);