diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index cfb227c..69fa504 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -905,7 +905,7 @@ class foldconst(object): rnt = rval.nt if optype == 'list' and not (ltype == rtype == 'list'): - if lnt == 'CONST' and not lval.value: + if lnt == 'CONST' and ltype == 'list' and not lval.value: # [] + nonlist -> (list)nonlist parent[index] = self.Cast(rval, optype) # node is SEF if rval is @@ -928,18 +928,26 @@ class foldconst(object): if optype in ('string', 'float', 'list'): # All these types evaluate to boolean False when they are # the neutral addition element. - if lnt == 'CONST' and not lval.value: - # 0. + expr -> expr - # "" + expr -> expr - # [] + expr -> expr + if lnt == 'CONST' and not lval.value and (ltype == rtype + or ltype == 'integer' and rtype == 'float' + or ltype == 'float' and rtype == 'integer'): + # 0 + fval -> fval + # 0. + fval -> fval + # 0. + ival -> fval + # "" + sval -> sval + # [] + lval -> lval parent[index] = self.Cast(rval, optype) # node is SEF if rval is parent[index].SEF = rval.SEF return - if rnt == 'CONST' and not rval.value: - # expr + 0. -> expr - # expr + "" -> expr - # expr + [] -> expr + if rnt == 'CONST' and not rval.value and (rtype == ltype + or rtype == 'integer' and ltype == 'float' + or rtype == 'float' and ltype == 'integer'): + # fval + 0 -> fval + # fval + 0. -> fval + # ival + 0. -> fval + # sval + "" -> sval + # lval + [] -> lval parent[index] = self.Cast(lval, optype) # node is SEF if lval is parent[index].SEF = lval.SEF diff --git a/unit_tests/regression.suite/issue-13.lsl b/unit_tests/regression.suite/issue-13.lsl new file mode 100644 index 0000000..ae11009 --- /dev/null +++ b/unit_tests/regression.suite/issue-13.lsl @@ -0,0 +1,10 @@ +default +{ + state_entry() + { + llParticleSystem("" + llGetPhysicsMaterial()); + llParticleSystem((list)"" + llGetPhysicsMaterial()); + llParticleSystem(0 + llGetPhysicsMaterial()); + llParticleSystem((list)0 + llGetPhysicsMaterial()); + } +} diff --git a/unit_tests/regression.suite/issue-13.out b/unit_tests/regression.suite/issue-13.out new file mode 100644 index 0000000..72dc38c --- /dev/null +++ b/unit_tests/regression.suite/issue-13.out @@ -0,0 +1,10 @@ +default +{ + state_entry() + { + llParticleSystem("" + llGetPhysicsMaterial()); + llParticleSystem("" + llGetPhysicsMaterial()); + llParticleSystem(0 + llGetPhysicsMaterial()); + llParticleSystem(0 + llGetPhysicsMaterial()); + } +} diff --git a/unit_tests/regression.suite/list-plus-elem.lsl b/unit_tests/regression.suite/list-plus-elem.lsl index 7ddffbf..505fa44 100644 --- a/unit_tests/regression.suite/list-plus-elem.lsl +++ b/unit_tests/regression.suite/list-plus-elem.lsl @@ -23,5 +23,21 @@ default{timer(){ a = (list)(list)(list)(list)(list)[b] + a; a = (list)(list)(list)(list)(list)1 + a; a = (list)(list)(list)(list)(list)b + a; + a += (llGetPhysicsMaterial() + 0); + a += (llGetPhysicsMaterial() + 0.); + a += (llGetPhysicsMaterial() + ""); + a += (llGetPhysicsMaterial() + []); + a += (0 + llGetPhysicsMaterial()); + a += (0. + llGetPhysicsMaterial()); + a += ("" + llGetPhysicsMaterial()); + a += ([] + llGetPhysicsMaterial()); + a += ([] + llGetPhysicsMaterial() + []); + a += (0 + []); + a += (0. + []); + a += ("" + []); + a += ([] + 0); + a += ([] + 0.); + a += ([] + ""); + a += ([] + []); llParticleSystem(a); }} diff --git a/unit_tests/regression.suite/list-plus-elem.out b/unit_tests/regression.suite/list-plus-elem.out index f0e4e6a..2233ac5 100644 --- a/unit_tests/regression.suite/list-plus-elem.out +++ b/unit_tests/regression.suite/list-plus-elem.out @@ -24,6 +24,21 @@ default a = b + a; a = 1 + a; a = b + a; + a = a + (llGetPhysicsMaterial() + 0); + a = a + (llGetPhysicsMaterial() + ((float)0)); + a = a + (llGetPhysicsMaterial() + ""); + a = a + llGetPhysicsMaterial(); + a = a + (0 + llGetPhysicsMaterial()); + a = a + (((float)0) + llGetPhysicsMaterial()); + a = a + ("" + llGetPhysicsMaterial()); + a = a + llGetPhysicsMaterial(); + a = a + llGetPhysicsMaterial(); + a = a + 0; + a = a + ((float)0); + a = a + ""; + a = a + 0; + a = a + ((float)0); + a = a + ""; llParticleSystem(a); } }