# HG changeset patch
# User Sylvain <syt@logilab.fr>
# Date 1210004904 -7200
#      Mon May 05 18:28:24 2008 +0200
# Node ID a08fe38dcb4c9afc5c4bf2fb5cf5e13880d0bec3
# Parent  0110ae78db256dee0f86959420ce410cc1108f84
fix as_string bug corrupting simplified trees

diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -127,6 +127,7 @@
                             else:
                                 vref.parent.replace(vref, rhs)
                         else:
+                            # remove from groupby/orderby
                             select.remove(term)
                     elif rel is uidrel or rel.is_types_restriction():
                         # drop this relation
diff --git a/stmts.py b/stmts.py
--- a/stmts.py
+++ b/stmts.py
@@ -353,9 +353,9 @@
             # replace const value by variable value and set constant type to Int
             # to avoid quoting
             for vname, consts in self.stinfo['rewritten'].iteritems():
-                eid = consts[0].eval(kwargs)
-                vvalues[vname] = (consts[0].type, eid)
-                restriction.append('%s eid %s' % (vname, eid))
+                sconst = consts[0]
+                vvalues[vname] = (sconst.type, sconst.value)
+                restriction.append('%s eid %s' % (vname, sconst.eval(kwargs)))
                 for const in consts:
                     const.value = vname
                     const.type = 'Int'