www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10571] New: formattedWrite error with delegate and string

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

           Summary: formattedWrite error with delegate and string
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: yebblies gmail.com



I can't format a string into a delegate taking a 'const char[]'.  This seems
wrong to me.

----------------------------------

import std.format;

void main()
{
    string buf;
    formattedWrite((in char[] s) { buf ~= s; }, "%s", "hello");
    assert(buf == "hello");
}

----------------------------------

DMD v2.064 DEBUG
F:\documents\desktop\d\sourcecode\phobos\std\range.d(611): Error: static assert
"Cannot put a dchar into a void delegate(const(char[])) nothrow  safe"
F:\documents\desktop\d\sourcecode\phobos\std\format.d(1752):       
instantiated from here: put!(void delegate(const(char[])) nothrow  safe, dchar)
F:\documents\desktop\d\sourcecode\phobos\std\format.d(2146):       
instantiated from here: formatValue!(void delegate(const(char[])) nothrow
 safe, dchar, char)
F:\documents\desktop\d\sourcecode\phobos\std\format.d(1790):       
instantiated from here: formatRange!(void delegate(const(char[])) nothrow
 safe, string, char)
F:\documents\desktop\d\sourcecode\phobos\std\format.d(2996):        ... (1
instantiations, -v to show) ...
F:\documents\desktop\d\sourcecode\phobos\std\format.d(420):       
instantiatedfrom here: formatGeneric!(void delegate(const(char[])) nothrow
 safe, string, char)
testx.d(7):        instantiated from here: formattedWrite!(void
delegate(const(char[]) s) nothrow  safe, char, string)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 08 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10571


yebblies <yebblies gmail.com> changed:

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



*** This issue has been marked as a duplicate of issue 9823 ***

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |



Ok, maybe not.

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


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com




 I can't format a string into a delegate taking a 'const char[]'.  This seems
 wrong to me.
 
 ----------------------------------
 
 import std.format;
 
 void main()
 {
     string buf;
     formattedWrite((in char[] s) { buf ~= s; }, "%s", "hello");
     assert(buf == "hello");
 }
 
 ----------------------------------
Yup. The branches char/string don't work with a delegate sink that accepts a const(char)[]. Here is a somewhat reduced case. //---- import std.format; void main() { FormatSpec!char f; formatValue((const(char)[]){}, '本', f); formatValue((const(char)[]){}, "a", f); } //---- The root issue is that "formatValue" for wide characters doesn't actually work. It just calls "put" and hopes put will magically do the work :D formatValue for strings then also fails, because it has to compile the "%r" path (raw), which iterates over the string as a range (dchars), and then prints these raw with formatValue(dchar), which, again, doesn't work. The reason we haven't seen this failure in the testers yet, is that std.format is mostly unittest using Appender, and Appender *knows* how to transcode, making it a very poor choice for thorough testing. In any case, this gets fixed by my "put" fix: https://github.com/D-Programming-Language/phobos/pull/1439 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 29 2013