transform: do not detach things while itering
authorJean Privat <jean@pryen.org>
Wed, 26 Mar 2014 07:48:19 +0000 (03:48 -0400)
committerJean Privat <jean@pryen.org>
Fri, 25 Apr 2014 13:16:57 +0000 (09:16 -0400)
This invalidates the underlying iterator.

Signed-off-by: Jean Privat <jean@pryen.org>

src/transform.nit

index bf4b992..2a8dda2 100644 (file)
@@ -88,13 +88,14 @@ redef class AVardeclExpr
        #
        # Declarations are only useful for scope rules
        # Once names are associated with real objects, ther declaration become useless
-       # Therefore, if there is no initial value, then just detach it
+       # Therefore, if there is no initial value, then just ignore it
        # Else, replace it with a simple assignment
        redef fun accept_transform_visitor(v)
        do
                var nexpr = n_expr
                if nexpr == null then
-                       detach
+                       # do nothing
+                       # note: not detached because the collection is currently under iteration
                else
                        var nvar = v.builder.make_var_assign(self.variable.as(not null), nexpr)
                        replace_with(nvar)