D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6456 - toString fails with alias this when more than one field present
Summary: toString fails with alias this when more than one field present
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-08 11:22 UTC by Andrej Mitrovic
Modified: 2012-01-04 07:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2011-08-08 11:22:46 UTC
import std.stdio;
import std.conv;

struct Foo
{
    string toString() { return to!string(x); }
    alias x this;
    
    int x;
    int y;   // comment this out and the bug is gone
}

void main()
{
    auto foo = Foo();
    writeln(foo);
}

If you comment out "int y;" the bug is gone, otherwise you get back this little thingy:

D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(100): Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) does not match any function template declaration
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(100): Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) cannot deduce template function from argument types !(int)(Foo)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(100): Error: template instance errors instantiating template
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\format.d(1683): Error: template instance std.conv.to!(int).to!(Foo) error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\format.d(328):        instantiated from here: getNthInt!(Foo)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(678):        instantiated from here: formattedWrite!(LockingTextWriter,immutable(char),Foo)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1511):        instantiated from here: write!(Foo,char)
test.d(18):        instantiated from here: writeln!(Foo)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\format.d(328): Error: template instance std.format.getNthInt!(Foo) error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(678):        instantiated from here: formattedWrite!(LockingTextWriter,immutable(char),Foo)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1511):        instantiated from here: write!(Foo,char)
test.d(18):        instantiated from here: writeln!(Foo)
Failed: dmd -d -debug -w -wi -unittest -v -o- "test.d" -I"." >test.d.deps
Comment 1 Andrej Mitrovic 2012-01-04 07:03:57 UTC
Fixed in 2.057, but I don't know which pull fixed it.