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
964
964
$ initializerExprContext = InitializerExprContext::fromClassReflection ($ this );
965
965
foreach ($ this ->reflection ->getCases () as $ case ) {
966
966
$ valueType = null ;
967
- if ($ case instanceof ReflectionEnumBackedCase) {
967
+ if ($ case instanceof ReflectionEnumBackedCase && $ case -> hasBackingValue () ) {
968
968
$ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), $ initializerExprContext );
969
969
}
970
970
$ caseName = $ case ->getName ();
@@ -991,7 +991,7 @@ public function getEnumCase(string $name): EnumCaseReflection
991
991
992
992
$ case = $ this ->reflection ->getCase ($ name );
993
993
$ valueType = null ;
994
- if ($ case instanceof ReflectionEnumBackedCase) {
994
+ if ($ case instanceof ReflectionEnumBackedCase && $ case -> hasBackingValue () ) {
995
995
$ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), InitializerExprContext::fromClassReflection ($ this ));
996
996
}
997
997
Original file line number Diff line number Diff line change @@ -1163,6 +1163,15 @@ public function testBug8537(): void
1163
1163
$ this ->assertNoErrors ($ errors );
1164
1164
}
1165
1165
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
+
1166
1175
public function testBug8146 (): void
1167
1176
{
1168
1177
$ 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