Skip to content

Excluding all enum cases one by one does not simplify a return type when using getAllowedSubTypes involving an enum #10148

@stof

Description

@stof

Bug report

When an extension implements getAllowedSubTypes to define that the only allowed subtypes of an interface are a given class and an enum, I would except that handling each case of the enum would leave us with a type refined to the other class, just like it does for union types.

Code snippet that reproduces the problem

https://phpstan.org/r/deeced13-4be2-4ce2-86d8-ee547748f18a

Expected output

When running that with the jiripudil/phpstan-sealed-classes extension installed, I would expect no error.
This extension defines an AllowedSubTypesClassReflectionExtension reading the Sealed attribute to provide the allowed subtypes.

Replacing the sealed interface (for which the extension defines the 2 allowed subtypes) with a union type of the 2 allowed subtypes does not report the error: https://phpstan.org/r/0c528e9b-ab4d-4811-ba45-dbe16b42ffac

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions