Skip to content

Commit 67d3a88

Browse files
committed
Fix missing properties on UnitEnum and BackedEnum
1 parent a712907 commit 67d3a88

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nette/utils": "^3.2.5",
2424
"nikic/php-parser": "^4.13.2",
2525
"ondram/ci-detector": "^3.4.0",
26-
"ondrejmirtes/better-reflection": "5.0.6.2",
26+
"ondrejmirtes/better-reflection": "5.0.6.3",
2727
"phpstan/php-8-stubs": "0.1.41",
2828
"phpstan/phpdoc-parser": "^1.2.0",
2929
"react/child-process": "^0.6.4",

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,24 @@ public function testBug5868(): void
523523
]);
524524
}
525525

526+
public function testBug6385(): void
527+
{
528+
if (PHP_VERSION_ID < 80100) {
529+
$this->markTestSkipped('Test requires PHP 8.1.');
530+
}
531+
532+
$this->checkThisOnly = false;
533+
$this->checkUnionTypes = true;
534+
$this->analyse([__DIR__ . '/data/bug-6385.php'], [
535+
[
536+
'Access to an undefined property UnitEnum::$value.',
537+
43,
538+
],
539+
[
540+
'Access to an undefined property Bug6385\ActualUnitEnum::$value.',
541+
47,
542+
],
543+
]);
544+
}
545+
526546
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug6385;
4+
5+
use BackedEnum;
6+
use UnitEnum;
7+
8+
final class EnumValue
9+
{
10+
public readonly string $name;
11+
public readonly string $value;
12+
13+
public function __construct(
14+
BackedEnum | string $name,
15+
BackedEnum | string $value
16+
) {
17+
$this->name = $name instanceof BackedEnum ? $name->name : $name;
18+
$this->value = $value instanceof BackedEnum ? $value->name : $value;
19+
}
20+
}
21+
22+
enum ActualUnitEnum
23+
{
24+
25+
}
26+
27+
enum ActualBackedEnum: int
28+
{
29+
30+
}
31+
32+
class Foo
33+
{
34+
35+
public function doFoo(
36+
UnitEnum $unitEnum,
37+
BackedEnum $backedEnum,
38+
ActualUnitEnum $actualUnitEnum,
39+
ActualBackedEnum $actualBackedEnum
40+
)
41+
{
42+
echo $unitEnum->name;
43+
echo $unitEnum->value;
44+
echo $backedEnum->name;
45+
echo $backedEnum->value;
46+
echo $actualUnitEnum->name;
47+
echo $actualUnitEnum->value;
48+
echo $actualBackedEnum->name;
49+
echo $actualBackedEnum->value;
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)