The following code fails to compile:
////////////////////////////////////////
// https://dpaste.dzfl.pl/2573f6fb2ff5
import std.algorithm : map;
import std.array : join;
struct Test
{
pragma(msg, ["a", "b", "c", "d"].map!(a => a).join("\n"));
}
////////////////////////////////////////
Compiler output:
src/phobos/std/algorithm/iteration.d(455): Error: this.__lambda1 has no value
6 : Error: CTFE failed because of previous errors in map
6 : called from here: join(map(["a", "b", "c", "d"]), "\x0a")
6 : while evaluating pragma(msg, join(map(["a", "b", "c", "d"]), "\x0a"))
Compilation failed
////////////////////////////////////////
Expected compiler output:
a
b
c
d
-------------------------------------------------------
This code also fails (replacing the lambda with a function literal):
////////////////////////////////////////
import std.algorithm : map;
import std.array : join;
struct Test
{
// std/algorithm/iteration.d(455): Error: this.__funcliteral1 has no value
pragma(msg, ["a", "b", "c", "d"].map!(function (a) { return a; }).join("\n"));
}
-------------------------------------------------------
However, this works:
////////////////////////////////////////
import std.algorithm : map;
import std.array : join;
struct Test
{
pragma(msg, ["a", "b", "c", "d"].map!("a").join("\n"));
}
-------------------------------------------------------
And this works too:
////////////////////////////////////////
import std.algorithm : map;
import std.array : join;
struct Test
{
pragma(msg, ["a", "b", "c", "d"].map!(function string(string a) { return a; }).join("\n"));
}
Comment #1 by asumface — 2019-04-11T18:09:56Z
Adding a test case:
import std.algorithm;
enum a = [1.0].map!(n => n); // works
struct Foo()
{
enum b = [1.0].map!(n => n); // identical line
}
void main()
{
pragma(msg, a);
pragma(msg, Foo!().b); // instantiation fails
}
Comment #2 by robert.schadek — 2024-12-13T18:52:47Z