[Issue 18543] New: Comments inside string mixin silently short-circuit code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 1 13:55:14 UTC 2018


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

--


More information about the Digitalmars-d-bugs mailing list