Thread overview
[Issue 12480] static assert should print out the string representation of a value it can interpret
Apr 20, 2014
Andrej Mitrovic
Apr 21, 2014
Per Nordlöw
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Per Nordlöw
Apr 21, 2014
Andrej Mitrovic
April 20, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://github.com/D-Progra
                   |                            |mming-Language/dmd/pull/347
                   |                            |4
           Assignee|nobody@puremagic.com        |andrej.mitrovich@gmail.com

--
April 20, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

--- Comment #1 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7ec47e158601f18a2dad86d7c594628da753a58a
Fix Issue 12480 - Implement better static assert diagnostics by doing CTFE
interpretation when optimizing static immutable arrays.

https://github.com/D-Programming-Language/dmd/commit/8903f3f8342f9476721470e19c53a10eb31bc31b Merge pull request #3474 from AndrejMitrovic/Fix12480

Issue 12480 - Implement better static assert diagnostics for static immutable arrays.

--
April 20, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

Per Nordlöw <per.nordlow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |per.nordlow@gmail.com

--- Comment #2 from Per Nordlöw <per.nordlow@gmail.com> ---
Is there pending work on a dynamic variant for this?

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to Per Nordlöw from comment #2)
> Is there pending work on a dynamic variant for this?

Can you elaborate?

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

--- Comment #4 from Per Nordlöw <per.nordlow@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.

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12480

--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to Per Nordlöw from comment #4)
> I've been wanting to have a similar dynamic behaviour

Ah you mean runtime. There is some related work on improving assert itself, although it doesn't go as far as you've talked about. See https://github.com/D-Programming-Language/dmd/pull/1426

--