Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for int-mask and int-mask-of types
- Loading branch information
1 parent
2d2f653
commit 7f5f55b
Showing
6 changed files
with
136 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
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,23 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug4732; | ||
|
||
class HelloWorld | ||
{ | ||
const FOO_BAR = 1; | ||
const FOO_BAZ = 2; | ||
|
||
/** | ||
* @param int-mask-of<self::FOO_*> $flags bitflags options | ||
*/ | ||
public static function sayHello(int $flags): void | ||
{ | ||
} | ||
|
||
public static function test(): void | ||
{ | ||
HelloWorld::sayHello(HelloWorld::FOO_BAR | HelloWorld::FOO_BAZ); | ||
HelloWorld::sayHello(HelloWorld::FOO_BAR); | ||
HelloWorld::sayHello(HelloWorld::FOO_BAZ); | ||
} | ||
} |
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,43 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace IntMask; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
const FOO_BAR = 1; | ||
const FOO_BAZ = 2; | ||
|
||
const BAZ_FOO = 1; | ||
const BAZ_BAR = 4; | ||
|
||
const BAR_INT = 1; | ||
const BAR_STR = ''; | ||
|
||
/** | ||
* @param int-mask-of<self::FOO_*> $one | ||
* @param int-mask<self::FOO_BAR, self::FOO_BAZ> $two | ||
* @param int-mask<1, 2, 8> $three | ||
* @param int-mask<1, 4, 16, 64, 256, 1024> $four | ||
* @param int-mask-of<self::BAZ_*> $five | ||
*/ | ||
public static function test(int $one, int $two, int $three, int $four, int $five): void | ||
{ | ||
assertType('int<0, 3>', $one); | ||
assertType('int<0, 3>', $two); | ||
assertType('0|1|2|3|8|9|10|11', $three); | ||
assertType('0|1|4|5|16|17|20|21|64|65|68|69|80|81|84|85|256|257|260|261|272|273|276|277|320|321|324|325|336|337|340|341|1024|1025|1028|1029|1040|1041|1044|1045|1088|1089|1092|1093|1104|1105|1108|1109|1280|1281|1284|1285|1296|1297|1300|1301|1344|1345|1348|1349|1360|1361|1364|1365', $four); | ||
assertType('0|1|4|5', $five); | ||
} | ||
|
||
/** | ||
* @param int-mask-of<self::BAR_*> $one | ||
* @param int-mask<0, 1, false> $two | ||
*/ | ||
public static function invalid(int $one, int $two, int $three): void | ||
{ | ||
assertType('int', $one); // not all constant integers | ||
assertType('int', $two); // not all constant integers | ||
} | ||
} |