[Issue 12480] static assert should print out the string representation of a value it can interpret

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Apr 21 02:15:49 PDT 2014


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

--- Comment #4 from Per Nordlöw <per.nordlow at gmail.com> ---
Elaboration from my previous post:

I'v been wanting to have a similar dynamic behaviour for

assert(EXPR)

where EXPR is of the form

x OP y

where OP typically is a logical comparison operator ==, !=, <, >, <=, >=.

For example if

assert(x == y)

fails it should in some useful way explain to the user why it failed.

For small structures (for example builtin scalar types) it could just print
them.

For larger structures/ranges it would be more useful to print the first (index,
value) of x and y where the assertion failed. This should probably apply
recursively, for example

Exception: assert(x == y) failed for i:th element of j:th element of ... x
being X and ... of y being Y

For large structures this may result in a significant increase in code
generation (and compilation time) for all the to!string instantiations the
needs to be made. Maybe a compiler flag is motivated in this case.

--


More information about the Digitalmars-d-bugs mailing list