October 03, 2014 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 --- Comment #19 from Artem Borisovskiy <kolos80@bk.ru> --- > If the loop index is mutable, then I think > it's OK to make it shared across loop iterations. Ridiculous. ---------------------------------- void delegate()[] dgList; const count = 10; // 1 for (int i = 0; i < count; ++i) dgList ~= { writeln(i); } // 2 foreach (immutable i; iota(count)) dgList ~= { writeln(i); } ---------------------------------- Why should 1 and 2 behave differently? Lambdas should capture outer variables in a consistent way - by copying them to their activation record, just as all other languages do. If you really want to capture the counter itself, you should use a pointer, although it doesn't make sense either, because you'll get an address of a stack-allocated variable. -- |
October 03, 2014 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 --- Comment #20 from Gabor Mezo <gabor.mezo@outlook.com> --- I agree. This is a bug definitely and shuld be addressed as soon as possible. -- |
May 01, 2015 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Hardware|x86 |All OS|Windows |All --- Comment #21 from Walter Bright <bugzilla@digitalmars.com> --- The most practical solution is to simply disallow referencing variables from a dynamic closure that end sooner than the closing } of the function. 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. -- |
May 02, 2015 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 --- Comment #22 from Ketmar Dark <ketmar@ketmar.no-ip.org> --- i.e. forbid closures at all. i wonder how should i pass additional parameter to std.alporithm.map predicate though. -- |
May 02, 2015 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 --- Comment #23 from Artem Borisovskiy <kolos80@bk.ru> --- (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. > > 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. Well, if you think it's the most practical solution, then would you kindly provide us with a couple of examples showing the solution from different angles? It isn't clear how it solves the problem. -- |
May 02, 2015 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 --- Comment #24 from timon.gehr@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. -- |
April 08, 2016 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 Edwin van Leeuwen <edder@tkwsping.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |edder@tkwsping.nl -- |
April 09, 2016 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 ZombineDev <petar.p.kirov@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |petar.p.kirov@gmail.com -- |
October 06, 2017 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 calex <calex+bugzilla-mail@aristoweb.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |calex+bugzilla-mail@aristow | |eb.net -- |
January 06, 2018 [Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2043 ag0aep6g@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |alexandru.razvan.c@gmail.co | |m --- Comment #25 from ag0aep6g@gmail.com --- *** Issue 18201 has been marked as a duplicate of this issue. *** -- |
Copyright © 1999-2021 by the D Language Foundation