Skip to content

Commit

Permalink
Allow enum cases to reference constants
Browse files Browse the repository at this point in the history
Fixes #8242
  • Loading branch information
weirdan committed Nov 10, 2022
1 parent 410c7bb commit 290b65f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -1371,7 +1371,7 @@ private function visitEnumDeclaration(
$stmt->expr,
$this->aliases,
$this->file_scanner,
null, // enum case value expressions cannot reference constants
$storage->constants, // enum case value expressions cannot reference constants
$fq_classlike_name
);

Expand Down
16 changes: 16 additions & 0 deletions tests/EnumTest.php
Expand Up @@ -440,6 +440,22 @@ function foo(): Code|null
'ignored_issues' => [],
'php_version' => '8.1',
],
'constantAsACaseValueOfABackedEnum' => [
'code' => '<?php
enum Test: string
{
public const ENUM_VALUE = "forty two";
case TheAnswer = self::ENUM_VALUE;
}
$a = Test::TheAnswer->value;
',
'assertions' => [
'$a===' => "'forty two'",
],
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}

Expand Down

0 comments on commit 290b65f

Please sign in to comment.