D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8044 - Print names, not casted values when using enum template parameter
Summary: Print names, not casted values when using enum template parameter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic, pull
: 14067 18479 (view as issue list)
Depends on:
Blocks:
 
Reported: 2012-05-04 20:33 UTC by Andrej Mitrovic
Modified: 2020-10-15 00:30 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-05-04 20:33:56 UTC
enum Enum { Foo, Bar }
void test(Enum en)()
    if(0)
{ 
}

void main()
{
    test!(Enum.Bar)();
}

test.d(11): Error: template instance test!(cast(Enum)1) test!(cast(Enum)1) does not match template declaration test(Enum en) if (0)
test.d(11): Error: function expected before (), not test!(cast(Enum)1) of type void

This is really awful because when you have over a few dozen fields in an enum you end up having to count the fields to figure out which enum value was actually used when instantiating the template. (Either that or having to insert a to!string call just for debugging).

The above errors should be:

test.d(11): Error: template instance test!(Enum.Bar) test!(Enum.Bar) does not match template declaration test(Enum en) if (0)
test.d(11): Error: function expected before (), not test!(Enum.Bar) of type void
Comment 1 bearophile_hugs 2012-05-06 06:50:44 UTC
See also Issue 5004
Comment 2 bearophile_hugs 2014-02-02 07:40:43 UTC
Related problem:


import std.stdio;
enum Foo { A, B }
const Foo f = Foo.A;
enum Bar : ubyte { C, D }
const Bar b = Bar.C;
void main() {
    pragma(msg, f, " ", b);
    writeln(f, " ", b);
}


Output:

cast(Foo)0 cast(Bar)cast(ubyte)0u
A C


Expected output:

A C
A C
Comment 3 Dlang Bot 2020-10-09 23:18:25 UTC
@Geod24 created dlang/dmd pull request #11841 "Fix 8044 - Print name of enum passed a tmpl param" fixing this issue:

- Fix 8044 - Print name of enum passed a tmpl param

https://github.com/dlang/dmd/pull/11841
Comment 4 Mathias LANG 2020-10-10 00:11:11 UTC
*** Issue 14067 has been marked as a duplicate of this issue. ***
Comment 5 Mathias LANG 2020-10-10 00:12:16 UTC
*** Issue 18479 has been marked as a duplicate of this issue. ***
Comment 6 Dlang Bot 2020-10-15 00:30:10 UTC
dlang/dmd pull request #11841 "Fix 8044 - Print name of enum passed a tmpl param" was merged into master:

- 05bf5a11d82676f56751e3e69482df6c22c33a31 by Geod24:
  Fix 8044 - Print name of enum passed a tmpl param

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