[Issue 4966] Loops and closures break immutable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 19 09:01:05 PST 2010


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


Bruno Medeiros <bdom.pub+deebugz at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bdom.pub+deebugz at gmail.com
         Resolution|                            |DUPLICATE


--- Comment #1 from Bruno Medeiros <bdom.pub+deebugz at gmail.com> 2010-11-19 08:59:45 PST ---
There is not just one variable 'v', there are several "instances" of variable
'v', each of them created on each iteration of the loop. Each of them is
immutable during its lifecycle (and cease to exist after their lifecycle, by
definition).

The orthogonal solution is:
 * make each 'v' variable be heap-allocated (have unscoped lifecycle). This is
consistent to how variables work in the top scope in functions.

I'm starting to reconsider though, if closures should automatically make
variables be heap-allocated. Maybe its best to require a keyword/annotation in
such referenced variables, and make the code not compile if such keywords is
not present.

*** This issue has been marked as a duplicate of issue 2043 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list