From 8289c14c8127e70633e9d88f4f30146c9f1b5b93 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 31 Mar 2018 02:02:36 +0200 Subject: [PATCH] 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. --- lslopt/lslparse.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index c6d4040..51a7652 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -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()