[Issue 24469] non-constant nested delegate literal expression - Error on delegates causing memory corruption
https://issues.dlang.org/show_bug.cgi?id=24469 kinke changed: What|Removed |Added Severity|critical|regression --- Comment #3 from kinke --- Oh and this is a regression according to run.dlang.io - up to v2.078, DMD issued a 'Error: non-constant nested delegate literal expression `__lambda2`' error too; since v2.079, it allows compilation but crashes at runtime. --
[Issue 24469] non-constant nested delegate literal expression - Error on delegates causing memory corruption
https://issues.dlang.org/show_bug.cgi?id=24469 kinke changed: What|Removed |Added CC||ki...@gmx.net --- Comment #2 from kinke --- Full example, showing the crash with DMD (LDC issues a compile error instead - 'Error: non-constant nested delegate literal expression `__lambda2`'): ``` struct ExistenceChecker { bool delegate() checkExistenceFn; } ExistenceChecker makeExistenceChecker(string gemName) { return ExistenceChecker(() => gemName == "dummy"); } auto checker = makeExistenceChecker("test"); // => invalid non-constant initializer void main() { assert(!checker.checkExistenceFn()); } ``` --
[Issue 24469] non-constant nested delegate literal expression - Error on delegates causing memory corruption
https://issues.dlang.org/show_bug.cgi?id=24469 --- Comment #1 from Marcelo Silva Nascimento Mancini --- I was able to reduce the bug: ```d struct ExistenceChecker { ///Optional. bool delegate() checkExistenceFn; } ExistenceChecker makeExistenceChecker(string gemName) { return ExistenceChecker(() { return executeShell("gem list | grep "~gemName).status == 0; }); } ExistenceChecker[] chks = [ makeExistenceChecker("test") ]; ``` --