Found by me and maxter.
I have a related problem in LDC: https://github.com/ldc-developers/ldc/issues/4282
This SIGSEGFAULTS:
```d
enum Easing : void function(){identity = (){} }
void main(){Easing.identity();}
```
This doesn't:
```
enum : void function(){identity = (){} }
void main(){identity();}
```
Comment #1 by razvan.nitu1305 — 2024-01-08T11:25:18Z
As a workaround you can name the anonymous function and it works:
```
void fun() {}
enum Easing : void function()
{
identity = &fun
}
void main()
{
Easing.identity();
}
```
This is just to unblock you, I'm looking now into how to make it work as is.
Comment #2 by msnmancini — 2024-01-08T13:29:11Z
Hello RazvanN.
The solution I'm currently using, is by using this templated style:
```d
//TODO: Change (x) to (float x) for not generating templates needlessly
enum HipEasing : float function(float x)
{
identity = (x) => x,
}
```
I hope it may help in the bug lookup
Comment #3 by bugzilla — 2024-01-23T07:27:54Z
It looks like `identity` is being set to null, and the lambda is ignored.
Comment #4 by bugzilla — 2024-01-23T07:31:50Z
Here's the generated code (renaming main() to test()):
_D5test16Easing9__lambda2MFNaNbNiNfZv:
0000: C3 ret // the lambda
_D5test14testFZv:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: B9 00 00 00 00 mov ECX,0
0009: 31 C0 xor EAX,EAX
000b: 48 FF D0 call RAX
000e: 5D pop RBP
000f: C3 ret
Calling null will definitely seg fault.
Comment #5 by bugzilla — 2024-01-23T07:52:59Z
The difference between identity being an (){} vs &fun is the first is a direct function call the second is an address of a function.
I'm not sure yet if the former should be an error, or can be made to work. Having an enum of function names has never occurred to me.
Comment #6 by dlang-bot — 2024-01-30T05:57:01Z
@WalterBright created dlang/dmd pull request #16117 "bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT " mentioning this issue:
- bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT
https://github.com/dlang/dmd/pull/16117
Comment #7 by dlang-bot — 2024-01-30T23:41:51Z
dlang/dmd pull request #16117 "fix bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT " was merged into master:
- e957b77fb7d5c250554c10b8c16bb5112b22f07d by Walter Bright:
fix bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT
https://github.com/dlang/dmd/pull/16117