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

Scope confusion with if and while #905

Open
hanche opened this issue Jan 26, 2020 · 0 comments
Open

Scope confusion with if and while #905

hanche opened this issue Jan 26, 2020 · 0 comments

Comments

@hanche
Copy link

@hanche hanche commented Jan 26, 2020

Example (⬥ is my prompt):

⬥ if (x = $true; put $x) { echo $x }
Exception: variable $x not found
Traceback:
  [tty], line 1:
    if (x = $true; put $x) { echo $x }
  [tty], line 1:
    if (x = $true; put $x) { echo $x }
⬥ put $x
▶ $true

As can be seen, $x does exist after running the if. It should be in scope within the if body, for sure?

Of course,

⬥ x= if (x = $true; put $x) { echo $x }

works as expected, and is better code as it does not pollute the local namespace. But stil, I consider this a bug.

The same thing happens with while. In fact, that is how I discovered the bug – with a more complicated expression in place of $true, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.