Thread overview
[Issue 7857] New: File#write formats enum as a boolean.
Apr 08, 2012
Masahiro Nakagawa
Apr 08, 2012
Kenji Hara
Apr 08, 2012
Walter Bright
Apr 08, 2012
Masahiro Nakagawa
April 08, 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@puremagic.com
        ReportedBy: repeatedly@gmail.com


--- Comment #0 from Masahiro Nakagawa <repeatedly@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: -------
April 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7857


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-04-08 08:57:51 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7857



--- Comment #2 from github-bugzilla@puremagic.com 2012-04-08 09:21:55 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/a153ac3f3b757a388210952a782f022d9f9141a5 fix Issue 7857 - File#write formats enum as a boolean.

https://github.com/D-Programming-Language/phobos/commit/eec836074e7f321c2c9bb28e57ee33fc5a497480 Merge pull request #531 from 9rnsr/fix7857

Issue 7857 - File#write formats enum as a boolean.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7857


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-04-08 09:58:09 PDT ---
Should I mark this as fixed, then?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7857


Masahiro Nakagawa <repeatedly@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #4 from Masahiro Nakagawa <repeatedly@gmail.com> 2012-04-08 10:01:35 PDT ---
(In reply to comment #3)
> Should I mark this as fixed, then?

Oops. I forgot to close this issue.

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