[Issue 7857] New: File#write formats enum as a boolean.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 8 07:14:09 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7857

           Summary: File#write formats enum as a boolean.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: repeatedly at gmail.com


--- Comment #0 from Masahiro Nakagawa <repeatedly at gmail.com> 2012-04-08 07:14:50 PDT ---
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.

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


More information about the Digitalmars-d-bugs mailing list