[Issue 23923] New: `this` not captured by lazy expression
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 18 11:46:44 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23923
Issue ID: 23923
Summary: `this` not captured by lazy expression
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: accepts-invalid, wrong-code
Severity: normal
Priority: P3
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dlang-bugzilla at thecybershadow.net
////////// test.d //////////
@safe:
void delegate() later;
void lazyFun(lazy void expr)
{
later = { expr; };
}
class C
{
void virtualFunc() {}
final void run()
{
lazyFun({
virtualFunc();
}());
}
}
void main()
{
auto c = new C;
c.run();
later();
}
////////////////////////////
This program segfaults. The `this` pointer used by the `virtualFunc` call is
gone by the time it is evaluated.
I am not sure if this is accepts-invalid or wrong-code. On one hand, the lazy
expression does capture regular locals. On the other hand, one would think that
`lazy` would imply `scope`, so the implicit reference to `this` (or other
locals) would not be allowed.
--
More information about the Digitalmars-d-bugs
mailing list