Bug 14600 – Lambda with body allowed as template alias argument

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-18T10:24:00Z
Last change time
2015-05-18T19:16:42Z
Assigned to
nobody
Creator
johnch_atms

Comments

Comment #0 by johnch_atms — 2015-05-18T10:24:46Z
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.
Comment #1 by ketmar — 2015-05-18T18:51:51Z
it's actually a grammar issue. what `() => { writeln("testing"); }` does is returns `void delegate () { writeln("testing"); }`. i.e. `=> { writeln("testing"); }` is correctly parsed as *expression* which returns delegate. another thing is that compiler doesn't emit warnings by default. compiling the code with "-w" flag gives this message: Warning: calling z01.main.__lambda1 without side effects discards return value of type void function() @safe, prepend a cast(void) if intentional i think that the report can be closed as "not-a-bug". we'd better spam bugzilla with "make warnings opt-out instead of opt-in" requests. ;-)
Comment #2 by johnch_atms — 2015-05-18T19:16:42Z
You're right. I should have tested with -w.