www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17627] New: assert output in ctfe is irritating


          Issue ID: 17627
           Summary: assert output in ctfe is irritating
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andre s-e-a-p.de

assert(false, strVar) has to be used to output a string variable in CTFE. At
the moment there is no other possibility as pragma(msg, ...) and writeln is not
Also with the new CTFE it isn't 100% clear whether ctfeWriteln will come:
http://forum.dlang.org/post/ynqedyhlpbolyfmhfvei forum.dlang.org

For this example 

string test(string s)
    string tmp = s;
    tmp = tmp[4..$];
    assert(false, tmp);
    return tmp;

enum foo =

void main()
    enum bar = test(foo);

The output is (dmd 2.075.0-b2):

C:\Users\user\Desktop>rdmd app
app.d(6): Error: "1234\x0a5678\x0a"[4..10]
app.d(17):        called from here: test("1234\x0a5678\x0a")
Failed: ["dmd", "-v", "-o-", "app.d", "-I."]

Instead of the content of tmp, the full content is shown with the slice
information [4..10].
This output is in a real scenario quite irritating as the string is much longer
and a lot more logic is going on and also the string isn't passed back but a
structure. I already thought dmd isn't working at all, as the tmp variable
didn't changed its value. Only after having 5 looks at the minimal example
output, I saw the slice information.

Jul 09 2017