From 28de23a03b415fb53a9c17b58519357a3fb907a5 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 25 May 2024 20:04:33 +0200 Subject: [PATCH] Parser fix: Give error in state switch when ident is not a state --- lslopt/lslparse.py | 7 +++++-- unit_tests/regression.suite/state-global.err | 3 +++ unit_tests/regression.suite/state-global.lsl | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 unit_tests/regression.suite/state-global.err create mode 100644 unit_tests/regression.suite/state-global.lsl diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index 48c520b..4b05b71 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -1825,8 +1825,11 @@ list lazy_list_set(list L, integer i, list v) raise EParseSyntax(self) # State Switch only searches for states in the global scope name = self.tok[1] if self.tok[0] == 'IDENT' else 'default' - if name not in self.symtab[0] and (name not in self.globals - or self.globals[name]['Kind'] != 's'): + if (name not in self.symtab[0] + or self.symtab[0][name]['Kind'] != 's' + ) and (name not in self.globals + or self.globals[name]['Kind'] != 's' + ): raise EParseUndefined(self) self.NextToken() self.expect(';') diff --git a/unit_tests/regression.suite/state-global.err b/unit_tests/regression.suite/state-global.err new file mode 100644 index 0000000..0f55b63 --- /dev/null +++ b/unit_tests/regression.suite/state-global.err @@ -0,0 +1,3 @@ +default{timer(){state Z;}} + ^ +(Line 2 char 23): ERROR: Name not defined within scope diff --git a/unit_tests/regression.suite/state-global.lsl b/unit_tests/regression.suite/state-global.lsl new file mode 100644 index 0000000..88d6785 --- /dev/null +++ b/unit_tests/regression.suite/state-global.lsl @@ -0,0 +1,2 @@ +integer Z; +default{timer(){state Z;}}