From e30a4ea25d0bf749336dccbfff5cd86ed0cee003 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 28 Feb 2015 20:37:18 +0100 Subject: [PATCH] Fix addstrings option (oops). --- lslopt/lslfoldconst.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 036ec8d..7fb312b 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -225,8 +225,9 @@ class foldconst(object): op1 = lval['value'] op2 = rval['value'] if nt == '+': - if ltype != 'string' or rtype != 'string' or self.addstrings: - result = lslfuncs.add(op1, op2) + if ltype == rtype == 'string' and not self.addstrings: + return + result = lslfuncs.add(op1, op2) elif nt == '-': result = lslfuncs.sub(op1, op2) elif nt == '*': @@ -300,14 +301,14 @@ class foldconst(object): # Tough one. Remove neutral elements for the diverse types, # and more. - # Addition of integers, strings, and lists is associative + # Addition of integers, strings, and lists is associative. # Addition of floats, vectors and rotations would be, except # for FP precision. # TODO: associative addition of lists # Associative lists are trickier, because unlike the others, # the types of the operands may not be lists # so e.g. list+(integer+integer) != (list+integer)+integer. - if optype in ('integer', 'string'): + if optype == 'integer' or optype == 'string' and self.addstrings: if lnt == '+' and rnt == 'CONST' and lval['ch'][1]['nt'] == 'CONST': # (var + ct1) + ct2 -> var + (ct1 + ct2) child[1] = {'nt': '+', 't': optype, 'ch':[lval['ch'][1], rval], 'SEF':True}