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

          Issue ID: 18543
           Summary: Comments inside string mixin silently short-circuit
                    code
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

I have recently stumbled upon the following wrong behaviour inside string
mixins.

If you use a single line style comment (//) inside a string mixin, this will
silently short-circuit the code, leading to unexpected behaviour, as you can
see in the example bellow:

import std.stdio;

void main(string[] args)
{
    mixin(""
    ~"writeln(\"Hello\");"
    ~"// Some comment"                                                          
    ~"assert(0);"
    );  
}

The assert will never get triggered.

If you use multi-line comments (/* */) those are correctly recognized and
everything works as expected.

--

Reply via email to