www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18543] New: Comments inside string mixin silently

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: nobody puremagic.com
          Reporter: edi33416 gmail.com

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.

--
Mar 01 2018