mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Fix bug where types of expressions in vectors/rotations were not checked
E.g. this was a valid vector literal: <"",0,0> Parse_simple_expr didn't have that problem, though.
This commit is contained in:
parent
075d3aba0c
commit
8289c14c81
1 changed files with 11 additions and 6 deletions
|
@ -305,8 +305,8 @@ class parser(object):
|
|||
raise EParseInvalidField(self)
|
||||
|
||||
def autocastcheck(self, value, tgttype):
|
||||
"""Check if automatic dynamic cast is possible, and insert it if
|
||||
requested explicitly.
|
||||
"""Check if automatic dynamic cast is possible. If explicit casts are
|
||||
requested, insert one.
|
||||
"""
|
||||
tval = value.t
|
||||
if tval == tgttype:
|
||||
|
@ -733,8 +733,9 @@ class parser(object):
|
|||
pos = self.pos
|
||||
errorpos = self.errorpos
|
||||
tok = self.tok
|
||||
component3 = False
|
||||
try:
|
||||
ret.append(self.Parse_expression())
|
||||
component3 = self.Parse_expression()
|
||||
|
||||
# Checking here for '>' might parse a different grammar, because
|
||||
# it might allow e.g. <1,2,3==3>; as a vector, which is not valid.
|
||||
|
@ -751,6 +752,10 @@ class parser(object):
|
|||
self.errorpos = errorpos
|
||||
self.tok = tok
|
||||
|
||||
# We do this here to prevent a type mismatch above
|
||||
if component3 is not False:
|
||||
ret.append(self.autocastcheck(component3, 'float'))
|
||||
|
||||
# OK, here we are.
|
||||
inequality = self.Parse_shift() # shift is the descendant of inequality
|
||||
while self.tok[0] in ('<', '<=', '>=', '>'):
|
||||
|
@ -770,7 +775,7 @@ class parser(object):
|
|||
'KEY_VALUE', 'VECTOR_VALUE', 'ROTATION_VALUE', 'LIST_VALUE',
|
||||
'TRUE', 'FALSE', '++', '--', 'PRINT', '!', '~', '(', '['
|
||||
):
|
||||
ret.append(inequality)
|
||||
ret.append(self.autocastcheck(inequality, 'float'))
|
||||
return ret
|
||||
# This is basically a copy/paste of the Parse_inequality handler
|
||||
ltype = inequality.t
|
||||
|
@ -856,10 +861,10 @@ class parser(object):
|
|||
return nr(nt=CONST, t='integer', value=1 if tok0 == 'TRUE' else 0)
|
||||
if tok0 == '<':
|
||||
self.NextToken()
|
||||
val = [self.Parse_expression()]
|
||||
val = [self.autocastcheck(self.Parse_expression(), 'float')]
|
||||
self.expect(',')
|
||||
self.NextToken()
|
||||
val.append(self.Parse_expression())
|
||||
val.append(self.autocastcheck(self.Parse_expression(), 'float'))
|
||||
self.expect(',')
|
||||
self.NextToken()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue