I wasn't able to minimally reproduce this error. This is the code that is causing it:
```d
Feature FeatureMakeRubyGem(
string gemName,
string purpose,
VersionRange supportedVersion = VersionRange.init,
OS[] requiredOn = null,
Feature*[] dependencies = null
)
{
import std.process;
return Feature("Ruby Gem: "~gemName, purpose, ExistenceChecker([], [], (ref Terminal t, TargetVersion v, out ExistenceStatus where)
{
if(executeShell("gem list | grep "~gemName).status)
{
where = ExistenceStatus(ExistenceStatus.Place.notFound);
return false;
}
where = ExistenceStatus(ExistenceStatus.place.inPath);
return true;
}), Installation([], (ref Terminal t, ref RealTimeConsoleInput input, TargetVersion ver, Download[] content)
{
return wait(spawnShell("sudo gem install "~gemName)) == 0;
}), null, supportedVersion, requiredOn, dependencies);
}
```
More information on LDC Repository: https://github.com/ldc-developers/ldc/issues/4610 since this is catched as an error by LDC
Comment #1 by msnmancini — 2024-03-30T13:54:00Z
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")
];
```
Comment #2 by kinke — 2024-03-30T14:01:45Z
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());
}
```
Comment #3 by kinke — 2024-03-30T14:06:29Z
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.
Comment #4 by robert.schadek — 2024-12-13T19:34:20Z