Allow erasing vars via function-scope

This triggered an assert because the remove code had no idea how to
find the function scope.

Oops!
This commit is contained in:
Fabian Homborg 2021-08-04 17:54:58 +02:00
parent c7c67755d3
commit 0059192f61
2 changed files with 21 additions and 0 deletions

View File

@ -1251,6 +1251,13 @@ mod_result_t env_stack_impl_t::remove(const wcstring &key, int mode) {
result.global_modified = true;
} else if (query.local) {
result.status = remove_from_chain(locals_, key) ? ENV_OK : ENV_NOT_FOUND;
} else if (query.function) {
auto node = locals_;
while (node->next) {
node = node->next;
if (node->new_scope) break;
}
result.status = remove_from_chain(node, key) ? ENV_OK : ENV_NOT_FOUND;
} else {
DIE("Unknown scope");
}

View File

@ -806,3 +806,17 @@ end
test-function-scope
echo $funcvar $funcvar2
# CHECK:
function erase-funcvar
set -l banana 1
begin
set -l banana 2
set -ef banana
echo $banana
# CHECK: 2
end
echo $banana
# CHECK:
end
erase-funcvar