-
Notifications
You must be signed in to change notification settings - Fork 96
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
[BUG] Cannot shadow variables which are already declared readonly #666
Comments
So we need to improve this function code https://github.com/amber-lang/amber/blob/main/src/std/env.ab#L110 Maybe we can use a variable name less common like |
That would only fix the problem in this instance. I think a better solution would be to name-mangle local as well as global variables, by using |
Specifically, we would need to change https://github.com/amber-lang/amber/blob/main/src/modules/variable/init.rs#L72, and other lines like it. This is one reason I've been wanting to centralise all Bash variable name generation, so we don't have to go searching for all instances... but that may be a larger task than is called for at this point. |
Even better would be to just always assign a global ID. I'm trying a fix. |
However, since this affects the translation layer, it would be sensible to wait until @Ph0enixKM has merged his forthcoming PR. |
Describe the bug
The generated printf function tries create a local variable by the name "args". If this variable name was previously declared as readonly, bash exits with the error:
amber 0.4.0-alpha
rev: d3ceda3
To Reproduce
File:
name-collision.ab
Expected behavior
The scripts should not crash and be able to assign local variables.
We might need to use a prefix or generate variable names a user likely won't use in their own code. (Which would unfortunately make code more unreadable).
Additional context
Some discussions can be found here
https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00105.html
and here
https://lists.gnu.org/archive/html/bug-bash/2019-03/msg00150.html
In the
name-collision.ab
example given in this issue, the variable args is already assigned as global read-only variable:Relevant Parts:
and later a reassignment even if shadowed is rejected:
The text was updated successfully, but these errors were encountered: