From 18d19b46538f9e626b7f49543a886026448dcc42 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Mon, 19 Nov 2018 20:25:05 +0100 Subject: [PATCH] Fix bug where 1 + (2 + function) was folded as 4 + function After folding, our cached values changed under us. Re-cache them. --- lslopt/lslfoldconst.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 78fdb26..4052ce1 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -973,20 +973,32 @@ class foldconst(object): return self.FoldTree(parent, index) while lnt == 'CONST' and rnt == 'NEG' and rval.ch[0].nt == '~': - child[0].value += 1 - rval = child[1] = rval.ch[0].ch[0] - rnt = rval.nt + lval.value += 1 + child[1] = rval.ch[0].ch[0] # rtype doesn't change - assert rval.t == 'integer' + assert child[1].t == 'integer' self.FoldTree(parent, index) + node = parent[index] + nt, child = node.nt, node.ch + if nt != '+': + return + lval, rval = child[0], child[1] + lnt, rnt = lval.nt, rval.nt + ltype, rtype = lval.t, rval.t while lnt == 'CONST' and rnt == '~' and rval.ch[0].nt == 'NEG': lval.value -= 1 - rval = child[1] = rval.ch[0].ch[0] - rnt = rval.nt + child[1] = rval.ch[0].ch[0] # rtype doesn't change - assert rval.t == 'integer' + assert child[1].t == 'integer' self.FoldTree(parent, index) + node = parent[index] + nt, child = node.nt, node.ch + if nt != '+': + return + lval, rval = child[0], child[1] + lnt, rnt = lval.nt, rval.nt + ltype, rtype = lval.t, rval.t if lnt != 'CONST': # Neither is const.