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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 5 09:43:08 UTC 2020


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #6 from Walter Bright <bugzilla at digitalmars.com> ---
(In reply to Joseph Rushton Wakeling from comment #4)
> The problem is that phobos uses speculative compilation to detect if a struct defines toString - which swallows the aforementioned error message.

What writeln() could do is first speculatively check to see that the symbol
toString exists, and if it's there then compile it for keeps, rather than
speculatively checking to see if calling it compiles.

That way it won't be silently swallowing the errors in compiling the toString
call.

Re-categorizing as a problem in the std.stdio implementation of writeln().

A way to see if a symbol exists is to do something like:

    __traits(compiles, alias xxx = toString);

--


More information about the Digitalmars-d-bugs mailing list