[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat May 2 05:42:58 PDT 2015


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

--- Comment #24 from timon.gehr at gmx.ch ---
(In reply to Walter Bright from comment #21)
> The most practical solution is to simply disallow referencing variables from
> a dynamic closure that end sooner than the closing } of the function.
> 

Why? Lexical scoping exists for a reason.

> This leaves it up to the user to decide how to handle it, such as passing
> the variable explicitly as an argument, declaring the variable at function
> scope, or copying the variable to another declared at function scope.

It's up to the user anyway. Mandating the workaround may be the easiest to
implement, but it certainly isn't the right thing to do.

Of course, your suggestion might be implemented (*only for local scopes inside
loops, please*) as a temporary fix for type system unsoundness, but don't
assume that this will fix this issue.

--


More information about the Digitalmars-d-bugs mailing list