Bug 17547 – Compile-time map!(...) fails to compile inside a struct when using lambdas ("this.__lambda1 has no value")

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2017-06-24T22:40:51Z
Last change time
2024-12-13T18:52:47Z
Assigned to
No Owner
Creator
Alexandre Bléron
Moved to GitHub: dmd#19267 →

Comments

Comment #0 by alex.bleron — 2017-06-24T22:40:51Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19267 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB