File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -964,7 +964,7 @@ public function getEnumCases(): array
964964 $ initializerExprContext = InitializerExprContext::fromClassReflection ($ this );
965965 foreach ($ this ->reflection ->getCases () as $ case ) {
966966 $ valueType = null ;
967- if ($ case instanceof ReflectionEnumBackedCase) {
967+ if ($ case instanceof ReflectionEnumBackedCase && $ case -> hasBackingValue () ) {
968968 $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), $ initializerExprContext );
969969 }
970970 $ caseName = $ case ->getName ();
@@ -991,7 +991,7 @@ public function getEnumCase(string $name): EnumCaseReflection
991991
992992 $ case = $ this ->reflection ->getCase ($ name );
993993 $ valueType = null ;
994- if ($ case instanceof ReflectionEnumBackedCase) {
994+ if ($ case instanceof ReflectionEnumBackedCase && $ case -> hasBackingValue () ) {
995995 $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), InitializerExprContext::fromClassReflection ($ this ));
996996 }
997997
Original file line number Diff line number Diff line change @@ -1163,6 +1163,15 @@ public function testBug8537(): void
11631163 $ this ->assertNoErrors ($ errors );
11641164 }
11651165
1166+ #[RequiresPhp('>= 8.1 ' )]
1167+ public function testBug7927 (): void
1168+ {
1169+ $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-7927.php ' );
1170+ $ this ->assertCount (2 , $ errors );
1171+ $ this ->assertSame ('Enum case Bug7927\Test::One does not have a value but the enum is backed with the "int" type. ' , $ errors [0 ]->getMessage ());
1172+ $ this ->assertSame ('Enum case Bug7927\Test::Two does not have a value but the enum is backed with the "int" type. ' , $ errors [1 ]->getMessage ());
1173+ }
1174+
11661175 public function testBug8146 (): void
11671176 {
11681177 $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-8146b.php ' );
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug7927 ;
4+
5+ enum Test : int
6+ {
7+ case One;
8+ case Two;
9+ }
10+
11+ $ v = Test::One;
12+
13+ function doIt (Test $ v ) : string
14+ {
15+ switch ($ v )
16+ {
17+ case Test::One:
18+ return "One " ;
19+ case Test::Two:
20+ return "Two " ;
21+ default :
22+ throw new \ErrorException ("Unknown ' {$ v ->name }'. " );
23+ }
24+ }
25+
26+ echo doIt ($ v );
You can’t perform that action at this time.
0 commit comments