Fix "" + list_expr producing list_expr

The type checks were not strong enough. While on it, strengthen other similar checks as well.

Reported by @Tonaie. Fixes #13.
This commit is contained in:
Sei Lisa 2020-04-23 13:39:34 +02:00
parent 4d75f0f792
commit 0affbf13dd
5 changed files with 68 additions and 9 deletions

View file

@ -905,7 +905,7 @@ class foldconst(object):
rnt = rval.nt rnt = rval.nt
if optype == 'list' and not (ltype == rtype == 'list'): 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 # [] + nonlist -> (list)nonlist
parent[index] = self.Cast(rval, optype) parent[index] = self.Cast(rval, optype)
# node is SEF if rval is # node is SEF if rval is
@ -928,18 +928,26 @@ class foldconst(object):
if optype in ('string', 'float', 'list'): if optype in ('string', 'float', 'list'):
# All these types evaluate to boolean False when they are # All these types evaluate to boolean False when they are
# the neutral addition element. # the neutral addition element.
if lnt == 'CONST' and not lval.value: if lnt == 'CONST' and not lval.value and (ltype == rtype
# 0. + expr -> expr or ltype == 'integer' and rtype == 'float'
# "" + expr -> expr or ltype == 'float' and rtype == 'integer'):
# [] + expr -> expr # 0 + fval -> fval
# 0. + fval -> fval
# 0. + ival -> fval
# "" + sval -> sval
# [] + lval -> lval
parent[index] = self.Cast(rval, optype) parent[index] = self.Cast(rval, optype)
# node is SEF if rval is # node is SEF if rval is
parent[index].SEF = rval.SEF parent[index].SEF = rval.SEF
return return
if rnt == 'CONST' and not rval.value: if rnt == 'CONST' and not rval.value and (rtype == ltype
# expr + 0. -> expr or rtype == 'integer' and ltype == 'float'
# expr + "" -> expr or rtype == 'float' and ltype == 'integer'):
# expr + [] -> expr # fval + 0 -> fval
# fval + 0. -> fval
# ival + 0. -> fval
# sval + "" -> sval
# lval + [] -> lval
parent[index] = self.Cast(lval, optype) parent[index] = self.Cast(lval, optype)
# node is SEF if lval is # node is SEF if lval is
parent[index].SEF = lval.SEF parent[index].SEF = lval.SEF

View file

@ -0,0 +1,10 @@
default
{
state_entry()
{
llParticleSystem("" + llGetPhysicsMaterial());
llParticleSystem((list)"" + llGetPhysicsMaterial());
llParticleSystem(0 + llGetPhysicsMaterial());
llParticleSystem((list)0 + llGetPhysicsMaterial());
}
}

View file

@ -0,0 +1,10 @@
default
{
state_entry()
{
llParticleSystem("" + llGetPhysicsMaterial());
llParticleSystem("" + llGetPhysicsMaterial());
llParticleSystem(0 + llGetPhysicsMaterial());
llParticleSystem(0 + llGetPhysicsMaterial());
}
}

View file

@ -23,5 +23,21 @@ default{timer(){
a = (list)(list)(list)(list)(list)[b] + a; a = (list)(list)(list)(list)(list)[b] + a;
a = (list)(list)(list)(list)(list)1 + a; a = (list)(list)(list)(list)(list)1 + a;
a = (list)(list)(list)(list)(list)b + 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); llParticleSystem(a);
}} }}

View file

@ -24,6 +24,21 @@ default
a = b + a; a = b + a;
a = 1 + a; a = 1 + a;
a = b + 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); llParticleSystem(a);
} }
} }