mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 19:56:16 +08:00
Clean up check_global_scope_exists
check_global_scope_exists is meant to warn if the user creates a universal variable shadowing a global. In practice it always returned success (though it may print an error). Remove its return value and clean up the call sites. Also rename it to `warn_if_uvar_shadows_global`. No functional change in this commit.
This commit is contained in:
parent
64dddfc6ce
commit
485a945004
|
@ -244,17 +244,14 @@ static int validate_cmd_opts(const wchar_t *cmd,
|
|||
|
||||
// Check if we are setting a uvar and a global of the same name exists. See
|
||||
// https://github.com/fish-shell/fish-shell/issues/806
|
||||
static int check_global_scope_exists(const wchar_t *cmd, const set_cmd_opts_t &opts,
|
||||
const wcstring &dest, io_streams_t &streams,
|
||||
const parser_t &parser) {
|
||||
if (opts.universal) {
|
||||
auto global_dest = parser.vars().get(dest, ENV_GLOBAL);
|
||||
if (global_dest && parser.is_interactive()) {
|
||||
static void warn_if_uvar_shadows_global(const wchar_t *cmd, const set_cmd_opts_t &opts,
|
||||
const wcstring &dest, io_streams_t &streams,
|
||||
const parser_t &parser) {
|
||||
if (opts.universal && parser.is_interactive()) {
|
||||
if (parser.vars().get(dest, ENV_GLOBAL).has_value()) {
|
||||
streams.err.append_format(BUILTIN_SET_UVAR_ERR, cmd, dest.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
static void handle_env_return(int retval, const wchar_t *cmd, const wcstring &key,
|
||||
|
@ -636,8 +633,7 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
|||
if (retval != STATUS_CMD_OK) {
|
||||
ret = retval;
|
||||
} else {
|
||||
retval = check_global_scope_exists(cmd, opts, split->varname, streams, parser);
|
||||
if (retval != STATUS_CMD_OK) ret = retval;
|
||||
warn_if_uvar_shadows_global(cmd, opts, split->varname, streams, parser);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -763,14 +759,12 @@ 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);
|
||||
warn_if_uvar_shadows_global(cmd, opts, split->varname, streams, parser);
|
||||
// Set the value back in the variable stack and fire any events.
|
||||
int retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(new_values),
|
||||
streams, parser);
|
||||
|
||||
if (retval != STATUS_CMD_OK) return retval;
|
||||
return have_shadowing_global;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// The set builtin creates, updates, and erases (removes, deletes) variables.
|
||||
|
|
Loading…
Reference in New Issue
Block a user