Skip to content

Commit

Permalink
RangeFunctionReturnTypeExtension - fix internal ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 15, 2024
1 parent 7ef210c commit fe3895a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Type/Php/RangeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
continue;
}

$rangeSpanned = abs($endConstant->getValue() - $startConstant->getValue());

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.

Check failure on line 68 in src/Type/Php/RangeFunctionReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Binary operation "-" between float|int|string and float|int|string results in an error.
if ($rangeSpanned <= $stepConstant->getValue()) {
continue;
}

$rangeValues = range($startConstant->getValue(), $endConstant->getValue(), $stepConstant->getValue());
if (count($rangeValues) > self::RANGE_LENGTH_THRESHOLD) {
if ($startConstant instanceof ConstantIntegerType && $endConstant instanceof ConstantIntegerType) {
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,12 @@ public function testBug10979(): void
$this->assertNoErrors($errors);
}

public function testBug11026(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-11026.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/data/bug-11026.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Bug11026;

function (): void {
$a = range(1, 3/2);
};

0 comments on commit fe3895a

Please sign in to comment.