Bug 5048 – string enum type not recognized as a string

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-10-12T21:31:00Z
Last change time
2013-08-18T22:05:28Z
Keywords
rejects-valid
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2010-10-12T21:31:00Z
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.
Comment #1 by hsteoh — 2013-08-18T22:02:51Z
Seems like this bug no longer occurs on git HEAD (1a6da16ef112e03607574758b722698f2950b0de).
Comment #2 by hsteoh — 2013-08-18T22:05:28Z
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.)