From f071483fac5eb0f6080242c1a11141884a4b0607 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 10 Nov 2022 02:15:22 -0400 Subject: [PATCH] Allow enum cases to reference constants Fixes vimeo/psalm#8242 --- .../Reflector/ClassLikeNodeScanner.php | 2 +- tests/EnumTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index bbfa1b56045..c41ef591682 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -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 ); diff --git a/tests/EnumTest.php b/tests/EnumTest.php index b65d840ffd7..b9ab13302e9 100644 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -440,6 +440,22 @@ function foo(): Code|null 'ignored_issues' => [], 'php_version' => '8.1', ], + 'constantAsACaseValueOfABackedEnum' => [ + 'code' => 'value; + ', + 'assertions' => [ + '$a===' => "'forty two'", + ], + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; }