-
-
Notifications
You must be signed in to change notification settings - Fork 309
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
Temporary assignment to nonexistent variable leaves it equal to '' #532
Comments
I can confirm this bug. If the variable already had a value (like in the example in the docs), then the old value is preserved correctly after the temporary assignment, but if the variable was undefined, then it gets set to an empty string after the temporary assignment. |
Yup, it's a known bug. Whoever implemented it must have been too lazy to write correct code :( |
@xiaq Lines 246 to 251 in 4df00b0
Is there any reason behind this? Maybe we should just skip |
This change makes assignmentOp mutable only on temporary assignment, otherwise the outer Op needs to know how to deal with it. Theoretically, lvaluesOp should tell which variable is new, but it requires more changes to the underlying structures. This fixes elves#532.
It seems to me that the core challenge in fixing this is modifying the compiler to recognize that a sequence such as this:
Should result in this compilation error:
Note that I created that error by commenting out the first line. From the compiler's perspective the temporary assignment should be equivalent to commenting out the first line. The fix for this issue is trivial if you don't care that the compiler does not recognize The borderline trivial, incomplete, fix would mean that dereferencing an undefined var is caught at run-time rather than compile-time. Is that good enough? My knowledge of the Elvish compiler is almost zero so it's possible the fully correct fix is also borderline trivial. |
Initialization of variable slots were "hoisted" to the beginning of each scope. This commit moves that initialization to the command that declares the variable, which make it easier to resolve #1257 and #1235. Also properly handle variables that are created as part of a temporary assignment, addressing #532. There are some failing tests, which will be fixed in upcoming commits.
This will no longer be irrelevant when the temp assignment form gets deprecated and eventually removed (#1114). The |
Is this a known issue? I think
y
should be undefined as before.The text was updated successfully, but these errors were encountered: