Skip to content

False positive: Argument type error when passing backed enum to function expecting UnitEnum or BackedEnum #930

Closed

Description

@ahmed-rashad-alnaggar

When passing a backed enum to a function that expects a UnitEnum or BackedEnum, PHP Tools reports a type error even though the argument type is valid according to PHP’s type system.

Image

Here, Permissions is a backed enum, so it should be accepted as a valid UnitEnum.

✅ Expected behavior

No warning should be shown when passing a backed enum to a parameter typed as UnitEnum or BackedEnum.

Activity

  1. self-assigned this
    on Oct 12, 2025
  2. jakubmisek commented on Oct 12, 2025

    @jakubmisek
    Member

    There must be something else, UnitEnum<->enum does not produce any warnings (I used enum Month just for test):

    Image

    Is Permissions defined in vendor or in user's code?

  3. ahmed-rashad-alnaggar commented on Oct 13, 2025

    @ahmed-rashad-alnaggar
    Author

    After some tweaking, I found where the issue lies.

    This is the Permissions enum:

    <?php
    
    namespace App\Support\Authorization;
    
    use Filament\Support\Contracts\HasLabel;
    
    enum Permissions: string implements HasLabel
    {
        case UPDATE_GENERAL_SETTINGS = 'update:general_settings';
    }

    The issue occurs because the enum implements an interface.
    If I remove the interface, it is correctly recognized as a backed enum.

    So the problem is that any backed or unit enum implementing an interface is no longer recognized as a backed/unit enum.

  4. jakubmisek commented on Oct 13, 2025

    @jakubmisek
    Member

    Thank you for digging the details! That makes sense, we're obviously treating enum with an interface incorrectly.

    Will be fixed

  5. changed the issue type fromtoon Oct 13, 2025
  6. added this to the v1.63 milestone on Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions