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

Scoping of the right hand side of a var assignment #1829

Closed
1 task done
hanche opened this issue Aug 6, 2024 · 2 comments
Closed
1 task done

Scoping of the right hand side of a var assignment #1829

hanche opened this issue Aug 6, 2024 · 2 comments

Comments

@hanche
Copy link
Contributor

hanche commented Aug 6, 2024

What happened, and what did you expect to happen?

What happens:

⬥ var a = x
⬥ var a = [$a $a] ##
⬥ put $a
⮕ [$nil $nil]

Expected result should be [x x].

Clearly, the problem is that the right hand side of the assignment (marked ## in the above code) is within the scope of the variable being declared.

I think the correct behaviour (for some value of “correct” is to first evaluate the right hand side of the assignment, then create the new variable(s) and perform the assignment.

Others may disagree, and some may argue that this is a feature request rather than a bug. But if so, it is at least a documentation bug, since the exact behaviour is not documented.

Output of "elvish -version"

0.21.0-dev.0.20240724150116-9597a25e366b-dirty

Code of Conduct

@hanche hanche changed the title The right hand side of a var assignment Scoping of the right hand side of a var assignment Aug 6, 2024
@hanche
Copy link
Contributor Author

hanche commented Aug 7, 2024

This appears to have been introduced with commit 9597a25e where with was introduced.

@xiaq xiaq closed this as completed in 3889bd0 Aug 7, 2024
@xiaq
Copy link
Member

xiaq commented Aug 7, 2024

The original behavior is the intended one and was broken accidentally. A regression test should prevent this from happening in future!

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