Commit 62eb019
committed
bug symfony#61543 [TypeInfo] Prevent interfaces extending BackedEnum to be treated as BackedEnums (ettoredn)
This PR was merged into the 7.3 branch.
Discussion
----------
[TypeInfo] Prevent interfaces extending BackedEnum to be treated as BackedEnums
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues |
| License | MIT
Given
```
interface DummyBackedEnumInterface extends \BackedEnum
{
}
```
`TypeFactoryTrait.php::enum():249` throws exception `Class "DummyBackedEnumInterface" is not an enum` trying to get the backing type, which is not defined.
```
public static function enum(string $className, ?BuiltinType $backingType = null): EnumType
{
if (is_subclass_of($className, \BackedEnum::class)) {
if (null === $backingType) {
$reflectionBackingType = (new \ReflectionEnum($className))->getBackingType(); // <-- throws
$typeIdentifier = TypeIdentifier::INT->value === (string) $reflectionBackingType ? TypeIdentifier::INT : TypeIdentifier::STRING;
$backingType = new BuiltinType($typeIdentifier);
}
return new BackedEnumType($className, $backingType);
}
return new EnumType($className);
}
```
This PR is meant as a fix. Upgrading to 7.3 broke my project because of this issue.
The open problem is how TypeInfo should handle BackedEnums that have no backing type defined. Besides interfaces, I'm not aware of any other way this can happen.
An alternative would be to extend `BackedEnumType` to support undefined backing type.
Commits
-------
fe49578 [TypeInfo] Prevent interfaces extending BackedEnum to be treated as BackedEnumsFile tree
4 files changed
+21
-1
lines changed- src/Symfony/Component/TypeInfo
- Tests
- Fixtures
- TypeResolver
- TypeResolver
4 files changed
+21
-1
lines changedLines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
0 commit comments