mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
Push and pop for-block every run through the loop
We do the same in while loops. This clears the local variables every time. Fixes #10525
This commit is contained in:
parent
6921394db2
commit
bf9e5583ba
2 changed files with 14 additions and 2 deletions
|
@ -990,7 +990,6 @@ impl<'a> ParseExecutionContext {
|
|||
assert!(retval == EnvStackSetResult::ENV_OK);
|
||||
|
||||
trace_if_enabled_with_args(ctx.parser(), L!("for"), &arguments);
|
||||
let fb = ctx.parser().push_block(Block::for_block());
|
||||
|
||||
// We fire the same event over and over again, just construct it once.
|
||||
let evt = Event::variable_set(for_var_name.clone());
|
||||
|
@ -1014,7 +1013,11 @@ impl<'a> ParseExecutionContext {
|
|||
event::fire(ctx.parser(), evt.clone());
|
||||
|
||||
ctx.parser().libdata_mut().pods.loop_status = LoopStatus::normals;
|
||||
|
||||
// Push and pop the block again and again to clear variables
|
||||
let fb = ctx.parser().push_block(Block::for_block());
|
||||
self.run_job_list(ctx, block_contents, Some(fb));
|
||||
ctx.parser().pop_block(fb);
|
||||
|
||||
if self.check_end_execution(ctx) == Some(EndExecutionReason::control_flow) {
|
||||
// Handle break or continue.
|
||||
|
@ -1026,7 +1029,6 @@ impl<'a> ParseExecutionContext {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.parser().pop_block(fb);
|
||||
trace_if_enabled(ctx.parser(), L!("end for"));
|
||||
ret
|
||||
}
|
||||
|
|
|
@ -43,3 +43,13 @@ end
|
|||
# CHECK: foo set
|
||||
# CHECK: foo set
|
||||
# CHECK: foo set
|
||||
|
||||
for x in 1 2 3
|
||||
test $x -eq 2 && set -l foo bar
|
||||
echo foo value is $foo
|
||||
end
|
||||
# We keep the old value from outside the loop
|
||||
# CHECK: foo value is 3
|
||||
# CHECK: foo set
|
||||
# CHECK: foo value is bar
|
||||
# CHECK: foo value is 3
|
||||
|
|
Loading…
Reference in a new issue