From 704517e23786d72c3dcd8719c108e5211e48a32b Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sat, 19 Aug 2017 21:39:21 -0700 Subject: [PATCH] Fix `set --local` when var is not in local scope Fixes #4321 --- src/builtin_set.cpp | 3 +-- tests/set.err | 3 +++ tests/set.in | 7 +++++++ tests/set.out | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index 8d900f8b1..a14b8c4bd 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -646,12 +646,11 @@ static int set_var_array(const wchar_t *cmd, set_cmd_opts_t &opts, const wchar_t UNUSED(streams); if (opts.prepend || opts.append) { - int scope = compute_scope(opts); if (opts.prepend) { for (int i = 0; i < argc; i++) new_values.push_back(argv[i]); } - env_var_t var_str = env_get(varname, scope); + env_var_t var_str = env_get(varname, ENV_DEFAULT); wcstring_list_t var_array; if (!var_str.missing()) var_str.to_list(var_array); new_values.insert(new_values.end(), var_array.begin(), var_array.end()); diff --git a/tests/set.err b/tests/set.err index d6e567403..9f4b92c4d 100644 --- a/tests/set.err +++ b/tests/set.err @@ -14,3 +14,6 @@ $argle bargle: invalid var name #################### # Appending and prepending at same time works + +#################### +# Setting local scope when no local scope of the var uses the closest scope diff --git a/tests/set.in b/tests/set.in index 46415de69..8893210d3 100644 --- a/tests/set.in +++ b/tests/set.in @@ -47,3 +47,10 @@ logmsg Appending and prepending at same time works set -g var5 abc def set -a -p var5 0 x 0 set --show var5 + +logmsg Setting local scope when no local scope of the var uses the closest scope +set -g var6 ghi jkl +begin + set -l -a var6 mno + set --show var6 +end diff --git a/tests/set.out b/tests/set.out index 561d24cea..29e8bf82c 100644 --- a/tests/set.out +++ b/tests/set.out @@ -88,3 +88,15 @@ $var5[7]: length=1 value=|x| $var5[8]: length=1 value=|0| $var5: not set in universal scope + +#################### +# Setting local scope when no local scope of the var uses the closest scope +$var6: set in local scope, unexported, with 3 elements +$var6[1]: length=3 value=|ghi| +$var6[2]: length=3 value=|jkl| +$var6[3]: length=3 value=|mno| +$var6: set in global scope, unexported, with 2 elements +$var6[1]: length=3 value=|ghi| +$var6[2]: length=3 value=|jkl| +$var6: not set in universal scope +