diff --git a/src/env.cpp b/src/env.cpp index a54f47e0e..ef633e13a 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -182,11 +182,13 @@ void var_stack_t::push(bool new_scope) { // Copy local-exported variables auto top_node = top.get(); - if (!(top_node == this->global_env)) { - for (auto& var : top_node->env) { - if (var.second.exportv) { - // This should copy var - node->env.insert(var); + if (new_scope) { + if (!(top_node == this->global_env)) { + for (auto& var : top_node->env) { + if (var.second.exportv) { + // This should copy var + node->env.insert(var); + } } } }