D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16570 - [REG 2.072.0-b1] Enum member with interpreted initializer has type of initializer not enum
Summary: [REG 2.072.0-b1] Enum member with interpreted initializer has type of initial...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2016-10-01 23:14 UTC by basile-z
Modified: 2017-12-18 22:57 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 basile-z 2016-10-01 23:14:27 UTC
well, don't trust the title too much. Test case:

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
static immutable int _a = 0;

enum Regression /*:int*/ // OK with a type
{
    a = _a,
}

void main()
{
    Regression reg;
    with(Regression) final switch(reg)
    {
        case a:break;
    }
}
°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

error:

/tmp/temp_7FCE629C80B0.d(17,14): Error: cannot implicitly convert expression (0) of type int to Regression

The problem seems more that the enum type is not deduced from the assignations.
Anyway you'll tell me.
Comment 1 Martin Nowak 2016-10-02 22:50:48 UTC
cat > bug.d << CODE
static immutable int _a = 0;

enum Regression
{
    a = _a,
}

static assert(is(typeof(Regression.a) == Regression));
CODE
dmd -c bug
----
bug.d(8): Error: static assert  (is(int == Regression)) is false
----

Digger says that https://github.com/dlang/dmd/pull/5878 introduced the bug, seems reasonable (see https://github.com/dlang/dmd/pull/5878/files#diff-bbe16dab8171d70a98ca3272a1efcc4aR633).
Comment 2 Martin Nowak 2016-10-05 23:36:49 UTC
https://github.com/dlang/dmd/pull/6175
Comment 3 github-bugzilla 2016-10-08 03:01:27 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/620ecc2fa91dd88310a9205666fc0c826a778303
fix Issue 16570 - Enum member with interpreted...

...initializer has type of initializer not enum

- There is a very old (dmd 0.50 [¹]) mismatch of the CastExp's `to` type
  and the type painted on the CastExp (the latter being the basetype of
  the former, i.e. EnumType vs. int) in the result of
  `Expression.castTo(ed.type)`.
  Because of that difference interpreting castTo might unexpectedly use
  the basetype instead of the enum type for the enum initializer, and
  thus triggers the can't convert int to EnumType error.

- The trigger was introduced with the addition of a `e.ctfeInterpret` in
  denum.d (see 932be192e3).

- Comments on CastExp suggest that this type mismatch is actually
  intended, I don't see any reason for it though.

- Alternatively we could somehow fix ctfeInterpret to preserve CastExp's
  painted type.

[¹]: https://github.com/dlang/dmd/blob/bde09435d149c699490bb888b832228e0d31c221/src/cast.c#L321-L323respect

https://github.com/dlang/dmd/commit/fa464f3742f5b92324a20597489c475118a293cc
Merge pull request #6175 from MartinNowak/fix16570

fix Issue 16570 - Enum member with interpreted...
Comment 4 github-bugzilla 2016-10-09 18:50:43 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/620ecc2fa91dd88310a9205666fc0c826a778303
fix Issue 16570 - Enum member with interpreted...

https://github.com/dlang/dmd/commit/fa464f3742f5b92324a20597489c475118a293cc
Merge pull request #6175 from MartinNowak/fix16570
Comment 5 github-bugzilla 2016-11-04 09:05:21 UTC
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/620ecc2fa91dd88310a9205666fc0c826a778303
fix Issue 16570 - Enum member with interpreted...

https://github.com/dlang/dmd/commit/fa464f3742f5b92324a20597489c475118a293cc
Merge pull request #6175 from MartinNowak/fix16570
Comment 6 github-bugzilla 2017-12-06 10:13:46 UTC
Commit pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/6f3b7e6b306818c65327cd698da1e401685ca025
Modify test for issue 16570 to accomodate fix for issue 12385
Comment 7 github-bugzilla 2017-12-18 22:57:40 UTC
Commit pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/6f3b7e6b306818c65327cd698da1e401685ca025
Modify test for issue 16570 to accomodate fix for issue 12385