Fix scope leakage after exit function
This commit is contained in:
@@ -82,6 +82,7 @@ class Environment():
|
|||||||
signatureCheckresult = function.signature.check(args)
|
signatureCheckresult = function.signature.check(args)
|
||||||
if signatureCheckresult[0]:
|
if signatureCheckresult[0]:
|
||||||
self.appendScope(function.defaultArgs)
|
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.scopes[-1].update({ argName: argValue for argName, argValue in zip(function.arguments, list(signatureCheckresult[1:])) })
|
||||||
self.callStack.append(CallStackItem(name))
|
self.callStack.append(CallStackItem(name))
|
||||||
result = Type.void()
|
result = Type.void()
|
||||||
@@ -91,6 +92,7 @@ class Environment():
|
|||||||
result = r.value
|
result = r.value
|
||||||
self.callStack.pop(-1)
|
self.callStack.pop(-1)
|
||||||
self.popScope(mergeVariables=False)
|
self.popScope(mergeVariables=False)
|
||||||
|
self.removeScopesAfter(appendedScopeIndex)
|
||||||
return (True, result)
|
return (True, result)
|
||||||
raise IllegalFunctionInvocationException(f"{function.name}{function.signature.string}", f"{name}{argsTypesToString(args)}")
|
raise IllegalFunctionInvocationException(f"{function.name}{function.signature.string}", f"{name}{argsTypesToString(args)}")
|
||||||
return (False, None)
|
return (False, None)
|
||||||
@@ -151,6 +153,9 @@ class Environment():
|
|||||||
if mergeVariables:
|
if mergeVariables:
|
||||||
self.scopes[-1].update(lastScope)
|
self.scopes[-1].update(lastScope)
|
||||||
|
|
||||||
|
def removeScopesAfter(self, index):
|
||||||
|
del self.scopes[index:]
|
||||||
|
|
||||||
def scopesToString(self):
|
def scopesToString(self):
|
||||||
return "Scopes:\n" + ("\n".join([ f" [{i}]: {scope}" for i, scope in enumerate(self.scopes) ]))
|
return "Scopes:\n" + ("\n".join([ f" [{i}]: {scope}" for i, scope in enumerate(self.scopes) ]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user