From fc0f99064fc3c2ea2ba06425b402bffd71903bd4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 2 Oct 2022 18:25:28 +0200 Subject: [PATCH] Regression test --- .../Rules/Classes/InstantiationRuleTest.php | 9 +++ tests/PHPStan/Rules/Classes/data/bug-7594.php | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/PHPStan/Rules/Classes/data/bug-7594.php diff --git a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php index f223e01f8f..bb0b72a1d9 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php @@ -422,4 +422,13 @@ public function testBug7048(): void ]); } + public function testBug7594(): void + { + if (PHP_VERSION_ID < 80000) { + $this->markTestSkipped('Test requires PHP 8.0.'); + } + + $this->analyse([__DIR__ . '/data/bug-7594.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Classes/data/bug-7594.php b/tests/PHPStan/Rules/Classes/data/bug-7594.php new file mode 100644 index 0000000000..4ec8de9b59 --- /dev/null +++ b/tests/PHPStan/Rules/Classes/data/bug-7594.php @@ -0,0 +1,57 @@ += 8.0 + +namespace Bug7594; + +class HelloWorld +{ + + public const ABILITY_BUILD = 0; + public const ABILITY_MINE = 1; + public const ABILITY_DOORS_AND_SWITCHES = 2; + public const ABILITY_OPEN_CONTAINERS = 3; + public const ABILITY_ATTACK_PLAYERS = 4; + public const ABILITY_ATTACK_MOBS = 5; + public const ABILITY_OPERATOR = 6; + public const ABILITY_TELEPORT = 7; + public const ABILITY_INVULNERABLE = 8; + public const ABILITY_FLYING = 9; + public const ABILITY_ALLOW_FLIGHT = 10; + public const ABILITY_INSTABUILD = 11; //??? + public const ABILITY_LIGHTNING = 12; //??? + private const ABILITY_FLY_SPEED = 13; + private const ABILITY_WALK_SPEED = 14; + public const ABILITY_MUTED = 15; + public const ABILITY_WORLD_BUILDER = 16; + public const ABILITY_NO_CLIP = 17; + + public const NUMBER_OF_ABILITIES = 18; + + /** + * @param bool[] $boolAbilities + * @phpstan-param array $boolAbilities + */ + public function __construct( + private array $boolAbilities, + ){} + + /** + * Returns a list of abilities set/overridden by this layer. If the ability value is not set, the index is omitted. + * @return bool[] + * @phpstan-return array + */ + public function getBoolAbilities() : array{ return $this->boolAbilities; } + + public static function decode(int $setAbilities, int $setAbilityValues) : self{ + $boolAbilities = []; + for($i = 0; $i < self::NUMBER_OF_ABILITIES; $i++){ + if($i === self::ABILITY_FLY_SPEED || $i === self::ABILITY_WALK_SPEED){ + continue; + } + if(($setAbilities & (1 << $i)) !== 0){ + $boolAbilities[$i] = ($setAbilityValues & (1 << $i)) !== 0; + } + } + + return new self($boolAbilities); + } +}