Skip to content

Bad diagnostic for an enum member in an enum that use another enum as base type #5526

Open
@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

basile-z reported this on 2024-07-25T18:00:53Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24684

Description

For

```
enum A1 : int
{
    a,
    b,
}

enum A2 : A1
{
    c, // does not require +1
    d, // requires + 1
}  
```

The definition of A2.d causes the error

> /tmp/temp_7F4942E9C090.d(10,5): Error: comparison between different enumeration types `A2` and `A1`; If this behavior is intended consider using `std.conv.asOriginalType`

which makes no sense.

In fact the real problem is that `A2.d` violates the specification 18.1.5 (https://dlang.org/spec/enum.html#named_enums), specifically _"it is given the value of the previous EnumMember + 1_".

In consequence a better message would be that `d` value cannot be automatically defined because the base type does not support increment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions