[Issue 21929] delegates capture do not respect scoping

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 19 03:10:01 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21929

--- Comment #5 from Walter Bright <bugzilla at digitalmars.com> ---
The general rule for determining "what should happen here" when there are
abstractions around pointers (such as arrays, delegates, refs, outs, class
references, etc.), is to rewrite it in explicit terms of those pointers. The
(sometimes baffling) behavior is then exposed for what it actually is, and the
behavior should match.

Granted, there is a special kludge in the compiler to sometimes put the
variables referenced by the delegate into a closure allocated by the gc, but
that doesn't account for variables that go out of scope before the function
scope ends. There is no process to make a closure for them, and adding such a
capability is likely much more complication than added value, and so should
just be an error.

--


More information about the Digitalmars-d-bugs mailing list