If no uvars are available, fall back to global when setting

Otherwise `set -U foo bar` if uvars aren't available would simply not
set *anything*.
This commit is contained in:
Fabian Homborg 2021-04-11 11:07:44 +02:00
parent 52f56e2119
commit 980365735a
2 changed files with 6 additions and 3 deletions

View file

@ -805,6 +805,7 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, c
new_values = new_var_values_by_index(*split, argc, argv);
}
bool have_shadowing_global = check_global_scope_exists(cmd, opts, split->varname, streams, parser);
// Set the value back in the variable stack and fire any events.
std::vector<event_t> evts;
int retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(new_values),
@ -814,7 +815,7 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, c
}
if (retval != STATUS_CMD_OK) return retval;
return check_global_scope_exists(cmd, opts, split->varname, streams, parser);
return have_shadowing_global;
}
/// The set builtin creates, updates, and erases (removes, deletes) variables.

View file

@ -1170,10 +1170,12 @@ mod_result_t env_stack_impl_t::set(const wcstring &key, env_mode_flags_t mode,
mod_result_t result{ENV_OK};
if (query.has_scope) {
// The user requested a particular scope.
if (query.universal) {
//
// If we don't have uvars, fall back to using globals
if (query.universal && uvars()) {
set_universal(key, std::move(val), query);
result.uvar_modified = true;
} else if (query.global) {
} else if (query.global || (query.universal && !uvars())) {
set_in_node(globals_, key, std::move(val), flags);
result.global_modified = true;
} else if (query.local) {