[Issue 14600] New: Lambda with body allowed as template alias argument

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon May 18 03:24:46 PDT 2015


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

          Issue ID: 14600
           Summary: Lambda with body allowed as template alias argument
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: johnch_atms at hotmail.com

When run, the following program compiles without error but produces no output.

void test(alias d)() {
  d();
}

void main() {
  import std.stdio : writeln;
  test!(() => { writeln("testing"); });
}

Compare to the following code, which does not compile because the => syntax is
only supposed to work with simple expressions.

void test(void delegate() d) {
  d();
}

void main() {
  import std.stdio : writeln;
  test(() => { writeln("testing"); });
}

Maybe the restriction on the => syntax not allowing bracketed expressions
should be lifted. I've spotted code on github that assumes this style does 
actually work.

--


More information about the Digitalmars-d-bugs mailing list