Skip to content

Commit

Permalink
Fix missing properties on UnitEnum and BackedEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 17, 2022
1 parent a712907 commit 67d3a88
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"nette/utils": "^3.2.5",
"nikic/php-parser": "^4.13.2",
"ondram/ci-detector": "^3.4.0",
"ondrejmirtes/better-reflection": "5.0.6.2",
"ondrejmirtes/better-reflection": "5.0.6.3",
"phpstan/php-8-stubs": "0.1.41",
"phpstan/phpdoc-parser": "^1.2.0",
"react/child-process": "^0.6.4",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,24 @@ public function testBug5868(): void
]);
}

public function testBug6385(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}

$this->checkThisOnly = false;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-6385.php'], [
[
'Access to an undefined property UnitEnum::$value.',
43,
],
[
'Access to an undefined property Bug6385\ActualUnitEnum::$value.',
47,
],
]);
}

}
53 changes: 53 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-6385.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php // lint >= 8.1

namespace Bug6385;

use BackedEnum;
use UnitEnum;

final class EnumValue
{
public readonly string $name;
public readonly string $value;

public function __construct(
BackedEnum | string $name,
BackedEnum | string $value
) {
$this->name = $name instanceof BackedEnum ? $name->name : $name;
$this->value = $value instanceof BackedEnum ? $value->name : $value;
}
}

enum ActualUnitEnum
{

}

enum ActualBackedEnum: int
{

}

class Foo
{

public function doFoo(
UnitEnum $unitEnum,
BackedEnum $backedEnum,
ActualUnitEnum $actualUnitEnum,
ActualBackedEnum $actualBackedEnum
)
{
echo $unitEnum->name;
echo $unitEnum->value;
echo $backedEnum->name;
echo $backedEnum->value;
echo $actualUnitEnum->name;
echo $actualUnitEnum->value;
echo $actualBackedEnum->name;
echo $actualBackedEnum->value;

}

}

0 comments on commit 67d3a88

Please sign in to comment.