-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix int-range return type for range()
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug9573; | ||
|
||
class MyClass { | ||
|
||
/** @var list<positive-int> */ | ||
public array $array; | ||
|
||
/** | ||
* @param positive-int $count | ||
*/ | ||
public function __construct(int $count) { | ||
$this->array = range(1, $count); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace RangeIntRange; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param int<0,max> $a | ||
* @param int<0,max> $b | ||
*/ | ||
public function zeroToMax( | ||
int $a, | ||
int $b | ||
): void | ||
{ | ||
assertType('list<int<0, max>>', range($a, $b)); | ||
} | ||
|
||
/** | ||
* @param int<2,10> $a | ||
* @param int<5,20> $b | ||
*/ | ||
public function twoToTwenty( | ||
int $a, | ||
int $b | ||
): void | ||
{ | ||
assertType('list<int<2, 20>>', range($a, $b)); | ||
} | ||
|
||
/** | ||
* @param int<10,30> $a | ||
* @param int<5,20> $b | ||
*/ | ||
public function fifteenTo5( | ||
int $a, | ||
int $b | ||
): void | ||
{ | ||
assertType('list<int<5, 30>>', range($a, $b)); | ||
} | ||
|
||
public function knownRange( | ||
): void | ||
{ | ||
$a = 5; | ||
$b = 10; | ||
assertType('array{5, 6, 7, 8, 9, 10}', range($a, $b)); | ||
} | ||
|
||
public function knownLargeRange( | ||
): void | ||
{ | ||
$a = 5; | ||
$b = 100; | ||
assertType('non-empty-list<int<5, 100>>', range($a, $b)); | ||
} | ||
} |