Skip to content

Conversation

ettoredn
Copy link
Contributor

@ettoredn ettoredn commented Aug 27, 2025

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.

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@ettoredn ettoredn marked this pull request as ready for review August 27, 2025 20:25
@carsonbot carsonbot added this to the 7.3 milestone Aug 27, 2025
@ettoredn ettoredn force-pushed the fix/typeinfo-backedenum-interface branch from 0539a1e to e1b4b24 Compare August 27, 2025 20:40
@nicolas-grekas nicolas-grekas force-pushed the fix/typeinfo-backedenum-interface branch from e1b4b24 to fe49578 Compare August 28, 2025 09:38
@nicolas-grekas
Copy link
Member

Thank you @ettoredn.

@nicolas-grekas nicolas-grekas merged commit 62eb019 into symfony:7.3 Aug 28, 2025
8 of 11 checks passed
@ettoredn
Copy link
Contributor Author

Hi @nicolas-grekas, thanks for merging the PR. Should the change be included in the CHANGELOG-7.3.md?

@mtarld
Copy link
Contributor

mtarld commented Aug 28, 2025

As it's a bug fix, it's not needed @ettoredn 🙂

@fabpot fabpot mentioned this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants