Comment #0 by bearophile_hugs — 2011-03-19T07:11:03Z
This code compiles with no errors (DMD 2.052), but in my opinion it has to raise a compile-time error, because map() must statically refuse functions that return void:
import std.algorithm;
void foo() {}
void main() {
int[] data = [1, 2, 3];
map!((int i){ return foo(); })(data);
}
Comment #1 by bearophile_hugs — 2011-03-19T07:12:24Z
A simpler example:
import std.algorithm;
void foo(int x) {}
void main() {
int[] data = [1, 2, 3];
map!foo(data);
}
It seems that void lambda is not disallowed. DMD2.069 compiles the code below, which I think must not:
void f(T)(T x){}
unittest
{
import std.algorithm : map;
static assert (!__traits(compiles, [1].map!f));
static assert ( __traits(compiles, [1].map!(e => f(e))));
}
Comment #8 by razvan.nitu1305 — 2017-08-24T08:12:28Z
(In reply to Ryuichi OHORI from comment #7)
> It seems that void lambda is not disallowed. DMD2.069 compiles the code
> below, which I think must not:
>
> void f(T)(T x){}
>
> unittest
> {
> import std.algorithm : map;
> static assert (!__traits(compiles, [1].map!f));
> static assert ( __traits(compiles, [1].map!(e => f(e))));
> }
I cannot reproduce this on git HEAD (ubuntu 16.04 64-bit). The second static assert fails with the message "Error: static assert "Mapping function(s) must not return void: tuple(__lambda1)"". Closing as WORKSFORME