From 3b6f0bf739c77e1fb8fb5116ae89cd70a2ac96c2 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 12 Sep 2021 19:12:31 +0200 Subject: [PATCH] range() of numeric-strings can produce array of float|int --- .../Php/RangeFunctionReturnTypeExtension.php | 3 ++- .../Analyser/NodeScopeResolverTest.php | 1 + .../Analyser/data/range-numeric-string.php | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Analyser/data/range-numeric-string.php diff --git a/src/Type/Php/RangeFunctionReturnTypeExtension.php b/src/Type/Php/RangeFunctionReturnTypeExtension.php index 101cb8d09f..bc6bcee9fd 100644 --- a/src/Type/Php/RangeFunctionReturnTypeExtension.php +++ b/src/Type/Php/RangeFunctionReturnTypeExtension.php @@ -105,7 +105,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $numberType = new UnionType([new IntegerType(), new FloatType()]); $isNumber = $numberType->isSuperTypeOf($argType)->yes(); - if ($isNumber) { + $isNumericString = $argType->isNumericString()->yes(); + if ($isNumber || $isNumericString) { return new ArrayType(new IntegerType(), $numberType); } diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 937998df7e..f33db67112 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -503,6 +503,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-5562.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5615.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/array_map_multiple.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/range-numeric-string.php'); } /** diff --git a/tests/PHPStan/Analyser/data/range-numeric-string.php b/tests/PHPStan/Analyser/data/range-numeric-string.php new file mode 100644 index 0000000000..faddec206b --- /dev/null +++ b/tests/PHPStan/Analyser/data/range-numeric-string.php @@ -0,0 +1,22 @@ +', range($a, $b)); + } + +}