Let's get the semantic around closure fixed.

Walter Bright newshound2 at digitalmars.com
Wed May 19 03:09:03 UTC 2021


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 mailing list