diff --git a/src/Type/Accessory/AccessoryNonFalsyStringType.php b/src/Type/Accessory/AccessoryNonFalsyStringType.php index 6600512da1..53e854283d 100644 --- a/src/Type/Accessory/AccessoryNonFalsyStringType.php +++ b/src/Type/Accessory/AccessoryNonFalsyStringType.php @@ -184,7 +184,8 @@ public function toAbsoluteNumber(): Type public function toInteger(): Type { - return TypeCombinator::remove(new IntegerType(), new ConstantIntegerType(0)); + // Do not remove `0` since `(int) '00'` is still `0`. + return new IntegerType(); } public function toFloat(): Type diff --git a/tests/PHPStan/Analyser/nsrt/bug-10893.php b/tests/PHPStan/Analyser/nsrt/bug-10893.php index a2b8396dd5..0878d2f302 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-10893.php +++ b/tests/PHPStan/Analyser/nsrt/bug-10893.php @@ -10,16 +10,16 @@ function hasMicroseconds(\DateTimeInterface $value, string $str): bool { assertType('non-falsy-string&numeric-string', $str); - assertType('int|int<1, max>', (int)$str); - assertType('true', (int)$str !== 0); + assertType('int', (int)$str); + assertType('bool', (int)$str !== 0); assertType('non-falsy-string&numeric-string', $value->format('u')); - assertType('int|int<1, max>', (int)$value->format('u')); - assertType('true', (int)$value->format('u') !== 0); + assertType('int', (int)$value->format('u')); + assertType('bool', (int)$value->format('u') !== 0); assertType('non-falsy-string&numeric-string', $value->format('v')); - assertType('int|int<1, max>', (int)$value->format('v')); - assertType('true', (int)$value->format('v') !== 0); + assertType('int', (int)$value->format('v')); + assertType('bool', (int)$value->format('v') !== 0); assertType('float', $value->format('u') * 1e-6); assertType('float', $value->format('v') * 1e-3); diff --git a/tests/PHPStan/Analyser/nsrt/bug-12393b.php b/tests/PHPStan/Analyser/nsrt/bug-12393b.php index 7ec8f3012b..a21dcf561a 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-12393b.php +++ b/tests/PHPStan/Analyser/nsrt/bug-12393b.php @@ -177,7 +177,7 @@ function doStrings($nonEmpty, $nonFalsy, $numeric, $literal, $lower, $upper) { $this->foo = $nonEmpty; assertType('int', $this->foo); $this->foo = $nonFalsy; - assertType('int|int<1, max>', $this->foo); + assertType('int', $this->foo); $this->foo = $numeric; assertType('int', $this->foo); $this->foo = $literal; @@ -706,4 +706,3 @@ public function __toString(): string { return 'Foo'; } } - diff --git a/tests/PHPStan/Analyser/nsrt/non-falsy-string.php b/tests/PHPStan/Analyser/nsrt/non-falsy-string.php index 5e7e05f229..12ca4c3fac 100644 --- a/tests/PHPStan/Analyser/nsrt/non-falsy-string.php +++ b/tests/PHPStan/Analyser/nsrt/non-falsy-string.php @@ -11,7 +11,7 @@ class Foo { * @param truthy-string $truthyString */ public function bar($nonFalseyString, $truthyString) { - assertType('int|int<1, max>', (int) $nonFalseyString); + assertType('int', (int) $nonFalseyString); // Do not remove `0` since `(int) '00'` is still `0` // truthy-string is an alias for non-falsy-string assertType('non-falsy-string', $truthyString); }