elves/elvish

Scoping of the right hand side of a var assignment

Closed this issue · 2 comments

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

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

xiaq commented

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