Skip to content

Commit

Permalink
Resolve PHP_INT_MAX as positive integer
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored Sep 22, 2021
1 parent be79bce commit 0cde73f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,9 @@ private function resolveType(Expr $node): Type
if ($resolvedConstantName === '__COMPILER_HALT_OFFSET__') {
return new IntegerType();
}
if ($resolvedConstantName === 'PHP_INT_MAX') {
return IntegerRangeType::fromInterval(1, null);
}

$constantType = $this->reflectionProvider->getConstant($node->name, $this)->getValueType();

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 @@ -447,6 +447,12 @@ public function testBug5639(): void
$this->assertCount(0, $errors);
}

public function testBug5657(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5657.php');
$this->assertCount(0, $errors);
}

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

namespace Bug5657;

class HelloWorld
{
/**
* @param positive-int $totalParts
*/
public function sayHello(int $totalParts = PHP_INT_MAX): void
{
}
}

0 comments on commit 0cde73f

Please sign in to comment.