[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 15 05:48:44 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2043





------- Comment #4 from benoit at tionex.de  2008-08-15 07:48 -------
Given this, the Java syntax makes much sense.
There, a variable that is accessible from an anonymous class must be marked as
'final'. This makes it easy, because the variable can be copied to the
anonymous class.

Perhaps D should consider to recreate a new concept for closures.

E.g. the old nested closure which are not allocated on the heap can access
everything. And the new full closure can only access 'final' vars and is
created with a special syntax like the suggestion from Sean "& new {}". Then
not the outside stackframe is heap allocated, instead the closure has an
allocated from with a copy of the accessed final vars.


-- 



More information about the Digitalmars-d-bugs mailing list