June 24, 2017 [Issue 17547] New: Compile-time map!(...) fails to compile inside a struct when using lambdas ("this.__lambda1 has no value") | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17547 Issue ID: 17547 Summary: Compile-time map!(...) fails to compile inside a struct when using lambdas ("this.__lambda1 has no value") Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: alex.bleron@gmail.com 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")); } -- |
Copyright © 1999-2021 by the D Language Foundation