ldc/tests/codegen/gh3553.d
Martin Kinkelin 4ec8fc0089
Fix potentially wrong context pointers when calling delegate literals (#3554)
Don't simply forward the caller's context without checking whether the
lambda actually needs a parent context. Fixes #3553.
2020-09-09 12:56:02 +02:00

16 lines
283 B
D

// https://github.com/ldc-developers/ldc/issues/3553
// RUN: %ldc -run %s
auto makeDelegate(alias fn)(long l) {
auto callIt() {
return fn() * l;
}
return &callIt;
}
void main()
{
int i = 7;
auto dg = makeDelegate!(() => i)(3);
assert(dg() == 21);
}