D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21828 - Enum forward-references just assume int base type
Summary: Enum forward-references just assume int base type
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2021-04-15 10:41 UTC by Vladimir Panteleev
Modified: 2021-04-16 07:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2021-04-15 10:41:46 UTC
//////// test.d ////////
struct S
{
    enum E
    {
        e1 = 0,
    }
    E e;
    enum S s1 = S(E.e1);
}

SE se;

enum SE
{
    e1 = S.s1
}
////////////////////////

test.d(8,15): Error: cannot implicitly convert expression `S(E.e1)` of type `S` to `int`

If the declaration of `SE` and the use `SE se;` are reordered, the problem goes away.
Comment 1 Dlang Bot 2021-04-15 15:41:40 UTC
@RazvanN7 created dlang/dmd pull request #12437 "Fix Issue 21828 - Using enum of struct (containing another enum) before its declaration fails" fixing this issue:

- Fix Issue 21828 - Using enum of struct (containing another enum) before its declaration fails

https://github.com/dlang/dmd/pull/12437
Comment 2 Dlang Bot 2021-04-15 15:54:51 UTC
@BorisCarvajal created dlang/dmd pull request #12438 "Fix Issue 21828 - Using enum of struct (containing another enum) befo…" fixing this issue:

- Fix Issue 21828 - Using enum of struct (containing another enum) before its declaration fails

https://github.com/dlang/dmd/pull/12438
Comment 3 Boris Carvajal 2021-04-15 18:44:20 UTC
reduced test case:

----
E e;

enum E
{
    a = "x"
}
----

Forward references just assume int value.
Comment 4 Dlang Bot 2021-04-16 07:27:33 UTC
dlang/dmd pull request #12438 "Fix Issue 21828 - Enum forward-references just assume int base type" was merged into master:

- 38a016e434505cb642aab480142a40343e2b4174 by Boris Carvajal:
  Fix Issue 21828 - Enum forward-references just assume int base type

https://github.com/dlang/dmd/pull/12438