fish-shell/tests/checks/for.fish
Fabian Homborg 31d6abb177 Don't fire variable set event before entering a for-loop
Since #4376, for-loops would set the loop variable outside, so it
stays valid.

They did this by doing the equivalent of

```fish
set -l foo $foo
for foo in 1 2 3
```

And that first imaginary `set -l` would also fire a set-event.

Since there's no use for it and the variable isn't actually set, we
remove it.

Fixes #8384.
2021-10-28 16:32:58 +02:00

46 lines
793 B
Fish

# RUN: %fish %s
# A for-loop-variable is a local variable in the enclosing scope.
set -g i global
# implicit set -l i $i
for i in local
end
set -ql i && echo $i
# CHECK: local
# The loop variable is initialized with any previous value.
set -g j global
for j in
end
set -ql j && echo $j
# CHECK: global
# Loop variables exist only locally in the enclosing local scope.
# They do not modify other local/global/universal variables.
set -g k global
begin
for k in local1
echo $k
# CHECK: local1
for k in local2
end
echo $k
# CHECK: local2
end
echo $k
# CHECK: local1
end
echo $k
# CHECK: global
function foo --on-variable foo
echo foo set
end
for foo in 1 2 3
true
end
# CHECK: foo set
# CHECK: foo set
# CHECK: foo set