Summary: format("%s") of struct without toString
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from 2010-10-11 15:18:36 PDT ---
Given a plain struct like Foo, the to!string creates a good enough textual
representation of it:

import std.conv: to;
struct Foo { int x; }
void main() {
    assert(to!string(Foo(1)) == "Foo(1)");

A nomal writefln("%s") just prints "Foo":

import std.stdio: writeln, writefln;
struct Foo { int x; }
void main() {
    writeln(Foo(1)); // ==> Foo
    writefln("%s", Foo(1)); // ==> Foo

But the format("%s") doesn't work:

import std.string: format;
struct Foo { int x; }
void main() {
    assert(format("%s", Foo(1)) == "Foo(1)");

DMD 2.049 gives the error:
std.format.FormatError: std.format Can't convert test.Point to string: "string
toString()" not defined

I expect this format("%s") to return "Foo(1)" or "Foo" (I prefer "Foo(1)").

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to