I created a struct with an anonymous function member variable:
struct S
{
const foo=function(int x,int y,int z)=>x;
}
When I create an instance of S and call the function with three arguments, the arguments get shifted: x gets junk data, y gets the first argument, z gets the second argument, and the third argument is lost.
If I declare foo in the global scope of the module, the arguments are passed the way they should - x gets the first argument, y gets the second argument, z gets the third argument.
If I declare foo as a member variable of a class, I get a segmentation fault when I try to call foo.
Making foo a static, shared, or __gshared member does not solve the problem.
Declaring foo's type explicitly *DOES* solve the problem:
int function(int,int,int) foo=function(int x,int y,int z)=>x;
this does work.
I have encountered this bug on DMD64 D Compiler v2.059 running on Arch Linux 3.3.8-1.
Comment #1 by hsteoh — 2014-07-17T18:49:35Z
Hmm. On git HEAD, this code now produces this message:
----
test.d(3): Deprecation: variable test.S.foo const field with initializer should be static, __gshared, or an enum
----
Changing it to static, enum, or auto, doesn't exhibit the problem described.
Comment #2 by robert.schadek — 2024-12-13T18:00:28Z