mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
set: Only warn about uvar shadowing if the set succeeded
Otherwise there's really no point in doing so - we'd tell you that a universal $status is shadowing a global, but we haven't actually created one!
This commit is contained in:
parent
b004635bc9
commit
7810f4e8a1
2 changed files with 11 additions and 1 deletions
|
@ -765,11 +765,13 @@ 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);
|
new_values = new_var_values_by_index(*split, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn_if_uvar_shadows_global(cmd, opts, split->varname, streams, parser);
|
|
||||||
// Set the value back in the variable stack and fire any events.
|
// 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),
|
int retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(new_values),
|
||||||
streams, parser);
|
streams, parser);
|
||||||
|
|
||||||
|
if (retval == ENV_OK) {
|
||||||
|
warn_if_uvar_shadows_global(cmd, opts, split->varname, streams, parser);
|
||||||
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -905,3 +905,11 @@ echo $status
|
||||||
set --query
|
set --query
|
||||||
echo $status
|
echo $status
|
||||||
# CHECK: 255
|
# CHECK: 255
|
||||||
|
|
||||||
|
set -U status
|
||||||
|
# CHECKERR: set: Tried to modify the special variable 'status' with the wrong scope
|
||||||
|
set -S status
|
||||||
|
# CHECK: $status: set in global scope, unexported, with 1 elements
|
||||||
|
# CHECK: Variable is read-only
|
||||||
|
# CHECK: $status[1]: |2|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue