Skip to content

Commit 0cde73f

Browse files
authored
Resolve PHP_INT_MAX as positive integer
1 parent be79bce commit 0cde73f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/Analyser/MutatingScope.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,9 @@ private function resolveType(Expr $node): Type
19781978
if ($resolvedConstantName === '__COMPILER_HALT_OFFSET__') {
19791979
return new IntegerType();
19801980
}
1981+
if ($resolvedConstantName === 'PHP_INT_MAX') {
1982+
return IntegerRangeType::fromInterval(1, null);
1983+
}
19811984

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

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ public function testBug5639(): void
447447
$this->assertCount(0, $errors);
448448
}
449449

450+
public function testBug5657(): void
451+
{
452+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5657.php');
453+
$this->assertCount(0, $errors);
454+
}
455+
450456
/**
451457
* @param string $file
452458
* @return \PHPStan\Analyser\Error[]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Bug5657;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param positive-int $totalParts
9+
*/
10+
public function sayHello(int $totalParts = PHP_INT_MAX): void
11+
{
12+
}
13+
}

0 commit comments

Comments
 (0)