www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5048] New: string enum type not recognized as a string

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5048

           Summary: string enum type not recognized as a string
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg gmx.com> 2010-10-12 21:31:00
PDT ---
This program:

import std.stdio;

enum Val : string { a = "a", b = "b" }

void func(Val v1, Val v2)(int num)
{
    writeln("%s + %s -> %s", v1, v2, num);
}

void main()
{
}


fails to compile with this error:

prog.d(5): Error: arithmetic/string type expected for value-parameter, not Val
prog.d(5): Error: arithmetic/string type expected for value-parameter, not Val


However, you change Val to string in func's template parameters, then it does
compile. For some reason the compiler is not recognizing Val to be a string
type in func's template parameters. If I make Val an int, it works just fine
(well, make it an int and change the values of a and b to integers), so it
appears to be something to do with strings specifically.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 12 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5048


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |hsteoh quickfur.ath.cx
         Resolution|                            |WORKSFORME


--- Comment #1 from hsteoh quickfur.ath.cx 2013-08-18 22:02:51 PDT ---
Seems like this bug no longer occurs on git HEAD
(1a6da16ef112e03607574758b722698f2950b0de).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 18 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5048



--- Comment #2 from hsteoh quickfur.ath.cx 2013-08-18 22:05:28 PDT ---
I added an actual instantiation in main() in order to ensure that this isn't
just the compiler deferring compilation of the template; the code seems to
work:

-----
import std.stdio;

enum Val : string { a = "a", b = "b" }

void func(Val v1, Val v2)(int num)
{
    writefln("%s + %s -> %s", v1, v2, num);
}

void main()
{
    func!(Val.a, Val.b)(1);
}
-----

(I also fixed a typo writeln -> writefln.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 18 2013