Bug 6456 – toString fails with alias this when more than one field present
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-08-08T11:22:00Z
Last change time
2012-01-04T07:03:57Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2011-08-08T11:22:46Z
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 by andrej.mitrovich — 2012-01-04T07:03:57Z
Fixed in 2.057, but I don't know which pull fixed it.