-
Notifications
You must be signed in to change notification settings - Fork 0
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
Make names declared as constants immutable #13
Conversation
We might need another way to automatically test this due to the inability to catch errors in Source |
We could add some data structure (at the global level) and use it to track errors. And then inspect it in the tests. |
Could you clarify how we could use a data structure to track errors? For example, if the following is a test then an error will be thrown due to constant reassignment. parse_and_eval("const x = 2; x = 4; x;");
assert_equal(2, final_result); |
add #12
This is done by storing an additional variable (
is_variable
) which indicates whether a name was declared as a variable. When assigning a value to a name, the value of this variable is then checked. If it is true, (eg. for names declared withlet
), then the assignment is allowed. Otherwise, an error is thrown.