Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue in static scope during multiple runs of the code. #34

Closed
aniketsingh0104 opened this issue Jan 24, 2022 · 0 comments
Closed

Comments

@aniketsingh0104
Copy link
Member

aniketsingh0104 commented Jan 24, 2022

Context: Scope of the entire program is statically set only once. This can potentially create a problem while re-running the code without refreshing the browser. The static scope will persist if the user doesn't refresh the browser tab.

I have observed this while testing:

While running multiple cases one after other, the variables in scope of previous test case were interfering with the current test case variables. To resolve this in testing, I did a scope reset before each test case.

Possible scenario demonstration:

Code 1:

hi bhai;
bhai ye hai a = 7;
bye bhai;

Code 2:

hi bhai;
bhai ye hai a = 30, b = 4;
bye bhai;

Let's say this code 1 runs in the browser and then user runs code 2 in the browser without refreshing the tab, the variable "a" from code 1 will persist in the scope and while running code 2, an error will be thrown.

Possible solution:

in interpret method:

interpret(code: string) {
  const ast = this._parser.parse(code);
  InterpreterModule.getVisitor(ast.type).visitNode(ast);
  InterpreterModule.setCurrentScope(new Scope(null)); // this will make sure that scope is reset after running the code.
}
aniketsingh0104 added a commit that referenced this issue Feb 6, 2022
ristri pushed a commit that referenced this issue Feb 12, 2022
* fix: issue: #34

* fix: issue: #36

* fix: issues
@ristri ristri closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants