diff --git a/src/env.cpp b/src/env.cpp index 3bdbdd348..36e84e396 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -183,6 +183,8 @@ void var_stack_t::push(bool new_scope) { // Copy local-exported variables auto top_node = top.get(); + // Only if we introduce a new shadowing scope + // i.e. not if it's just `begin; end` or "--no-scope-shadowing". if (new_scope) { if (!(top_node == this->global_env)) { for (auto& var : top_node->env) { diff --git a/tests/test3.in b/tests/test3.in index 9ddae60a1..4387f9e94 100644 --- a/tests/test3.in +++ b/tests/test3.in @@ -257,6 +257,15 @@ set -lx var wuwuwu __fish_test_local_export echo $var +# Test that we don't copy local-exports to blocks. +set -lx var foo +begin + echo $var + set var bar + echo $var +end +echo $var # should be "bar" + # clear for other shells set -eU __fish_test_universal_variables_variable_foo diff --git a/tests/test3.out b/tests/test3.out index 3c30a3e1e..762548f59 100644 --- a/tests/test3.out +++ b/tests/test3.out @@ -23,6 +23,9 @@ __fish_test_env17=UNSHADOWED wuwuwu boo wuwuwu +foo +bar +bar Testing Universal Startup 1 1