From 3feec0839bfa61fa436ba9323b6937002b8516e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Tue, 16 Jul 2019 23:59:34 +0200 Subject: [PATCH] Fix scope leakage after exit function --- smnp/environment/environment.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/smnp/environment/environment.py b/smnp/environment/environment.py index 786f15d..08dfece 100644 --- a/smnp/environment/environment.py +++ b/smnp/environment/environment.py @@ -82,6 +82,7 @@ class Environment(): signatureCheckresult = function.signature.check(args) if signatureCheckresult[0]: self.appendScope(function.defaultArgs) + appendedScopeIndex = len(self.scopes)-1 self.scopes[-1].update({ argName: argValue for argName, argValue in zip(function.arguments, list(signatureCheckresult[1:])) }) self.callStack.append(CallStackItem(name)) result = Type.void() @@ -91,6 +92,7 @@ class Environment(): result = r.value self.callStack.pop(-1) self.popScope(mergeVariables=False) + self.removeScopesAfter(appendedScopeIndex) return (True, result) raise IllegalFunctionInvocationException(f"{function.name}{function.signature.string}", f"{name}{argsTypesToString(args)}") return (False, None) @@ -151,6 +153,9 @@ class Environment(): if mergeVariables: self.scopes[-1].update(lastScope) + def removeScopesAfter(self, index): + del self.scopes[index:] + def scopesToString(self): return "Scopes:\n" + ("\n".join([ f" [{i}]: {scope}" for i, scope in enumerate(self.scopes) ]))