Skip to content

Aliases for enum members must be considered in exhaustive case #16621

@straight-shoota

Description

@straight-shoota

When an enum contains aliases for a member, these aliases are currently required to be covered in exhaustive case:

enum Foo
  Bar
  Qux
  Baz = Qux
end
 
case Foo::Bar # Error: case is not exhaustive for enum Foo. Missing members: - Baz
in Foo::Bar
in Foo::Qux
end

This is rather inconvenient when Baz is an alias for Qux and both are supposed to be useable interchangeably.

A use case for this would be changing a member's name by adding a new member and keeping the old one as a deprecated alias (example: in #16354 we'd like to rename Redirect::Close to Redirect::Null).
The addition of an alias should not have an effect on exhaustive case behaviour.

There is a possibility that two members happen to share the same value, but are not exactly aliases. This could be the case for example when the values are defined externally, or may vary depending or depend on some configuration.
However, enums with flexible members are not relevant for exhaustive case, so it should be fine to ignore this. Just like we ignore arbitrary enum members like Foo.new(42) created at runtime.


Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions