Test code is below:
-----
enum EI : int
{
A, B
}
enum ED : double
{
A, B
}
writeln(EI.A); // false, but A on 2.058
writeln(EI.B); // true, but B on 2.058
writeln(ED.A); // A
writeln(ED.B); // B
-----
The reason of this bug is isBoolean template returns true.
(BooleanTypeOf template returns "immutable(bool)").
std.stdio.File#write's code:
-----
void write(S...)(S args)
{
auto w = lockingTextWriter;
foreach (arg; args)
{
alias typeof(arg) A;
static if (isSomeString!A)
{
put(w, arg);
}
else static if (isIntegral!A)
{
toTextRange(arg, w);
}
else static if (isBoolean!A) // Oops! enum into this block.
{
put(w, arg ? "true" : "false");
}
else static if (isSomeChar!A)
{
put(w, arg);
}
else
{
// Most general case
std.format.formattedWrite(w, "%s", arg);
}
}
}
-----
This bug is major issue for me.
Comment #1 by k.hara.pg — 2012-04-08T08:57:51Z
Not only a problem of integer based enum type.
import std.stdio;
void main()
{
enum EI : int { A, B }
enum ED : double { A, B }
enum EC : char { A, B }
enum ES : string { A = "aaa", B = "bbb" }
writeln(EI.A); // false, but A on 2.058
writeln(EI.B); // true, but B on 2.058
writeln(ED.A); // A
writeln(ED.B); // B
writeln(EC.A); // false
writeln(EC.B); // true
writeln(ES.A); // aaa
writeln(ES.B); // bbb
}
Pull request:
https://github.com/D-Programming-Language/phobos/pull/531
Comment #2 by github-bugzilla — 2012-04-08T09:21:55Z