diff --git a/src/builtins/set.cpp b/src/builtins/set.cpp index 0f72673d3..1b48cdd72 100644 --- a/src/builtins/set.cpp +++ b/src/builtins/set.cpp @@ -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); } - 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 == ENV_OK) { + warn_if_uvar_shadows_global(cmd, opts, split->varname, streams, parser); + } return retval; } diff --git a/tests/checks/set.fish b/tests/checks/set.fish index b06f3030b..4cfdb90fb 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -905,3 +905,11 @@ echo $status set --query echo $status # 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| +