[Issue 21228] Templated toString silently ignored when it can't be instantiated

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 6 14:41:03 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21228

--- Comment #5 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
A missing toString is not an error - struct S {} should print.

One issue is there's umpteen different possible signatures for toString, and we
don't know which was intended, so we could just be calling it wrong. Once we've
figured out none of the possible ways is correct, we can say for sure that
something's wrong, but not exactly what.

We could introduce something like __traits(getErrors, somecode) that would
return the resulting error messages from an invocation, but 1) we don't have
that, and 2) even if we did, inspecting error messages to figure out what's
wrong is error-prone, and the exact text of the error messages may change in
the future (at least until issue 10335 is implemented).

Perhaps a better option would be something like __traits(errorLocation,
someInstantiation), that would return "body", "arguments", "template
arguments", or "template constraints", depending on where the instantiation
fails. I'm still not sold on that, though.

--


More information about the Digitalmars-d-bugs mailing list