Hello,
if I declare a toString function protected, the compiler spills lots of error messages regardig Writers and Appenders.
I find this very unhelpful.
maybe another Template Contraint
something along the lines of
if (hasToString!T && isCallable!T.toString)
would be abit clearer.
Cheers
Uplink_Coder
Comment #1 by razvan.nitu1305 — 2017-09-05T11:59:36Z
Could you please offer an example and the output? The issue description is very vague.
Comment #2 by dfj1esp02 — 2017-09-05T13:42:39Z
I suppose something like this:
class A
{
protected override string toString(){ return null; }
}
void f()
{
import std.stdio;
write(new A);
}
std/format.d(3450): Error: template instance std.format.formatObject!(LockingTextWriter, A, char) does not match template declaration formatObject(Writer, T, Char)(ref Writer w, ref T val, ref const FormatSpec!Char f) if (hasToString!(T, Char))
Comment #3 by dfj1esp02 — 2017-09-05T13:48:44Z
Issue 9626 is for compiler diagnostic. But I'm not sure we want to patch this case by case instead of improving diagnostic in compiler.
Comment #4 by dfj1esp02 — 2017-09-05T13:55:16Z
And I think this can't be patched in phobos: formatObject can't work with protected toString, hence it must be skipped, which results in the generic template mismatch error.
Comment #5 by razvan.nitu1305 — 2017-09-05T14:00:33Z
There is nothing wrong with the compiler message. The toString method is not visible outside the module it was declared so the template constraint hasToString!(T, Char) fails (as it should). I think we should close this.
Comment #6 by razvan.nitu1305 — 2017-09-07T07:40:04Z