diff --git a/src/Type/Accessory/AccessoryDecimalIntegerStringType.php b/src/Type/Accessory/AccessoryDecimalIntegerStringType.php index d965eb0ebc..ebe0d3ce67 100644 --- a/src/Type/Accessory/AccessoryDecimalIntegerStringType.php +++ b/src/Type/Accessory/AccessoryDecimalIntegerStringType.php @@ -205,14 +205,13 @@ public function unsetOffset(Type $offsetType): Type public function toNumber(): Type { - if ($this->inverse) { - return new UnionType([ - $this->toInteger(), - $this->toFloat(), - ]); - } - - return $this->toInteger(); + // Decimal integer strings larger than PHP_INT_MAX (or smaller than + // PHP_INT_MIN) overflow to float when coerced to a number, so the + // numeric coercion is int|float even for non-inverse values. + return new UnionType([ + $this->toInteger(), + $this->toFloat(), + ]); } public function toAbsoluteNumber(): Type diff --git a/tests/PHPStan/Analyser/nsrt/bug-14786.php b/tests/PHPStan/Analyser/nsrt/bug-14786.php new file mode 100644 index 0000000000..b82afeb402 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-14786.php @@ -0,0 +1,38 @@ +treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-14786.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-14786.php b/tests/PHPStan/Rules/Comparison/data/bug-14786.php new file mode 100644 index 0000000000..db5b4d12bb --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-14786.php @@ -0,0 +1,17 @@ +