Bug 16570 – [REG 2.072.0-b1] Enum member with interpreted initializer has type of initializer not enum
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-10-01T23:14:27Z
Last change time
2017-12-18T22:57:40Z
Keywords
pull
Assigned to
No Owner
Creator
Basile B.
Comments
Comment #0 by b2.temp — 2016-10-01T23:14:27Z
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 #3 by github-bugzilla — 2016-10-08T03:01:27Z
Commits pushed to stable at https://github.com/dlang/dmdhttps://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-L323respecthttps://github.com/dlang/dmd/commit/fa464f3742f5b92324a20597489c475118a293cc
Merge pull request #6175 from MartinNowak/fix16570
fix Issue 16570 - Enum member with interpreted...
Comment #4 by github-bugzilla — 2016-10-09T18:50:43Z