commit 3933592338934933adfeb35dca8472bd28838ec8
parent d98e5357af1cd64b3e21196bc8e2408c724c0625
Author: Andrey Mishchenko <mishchea@gmail.com>
Date: Tue, 26 Apr 2022 23:58:25 -0400
fix: has() should preserve v:shell_error #18280
fixes #18278
Diffstat:
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
@@ -4278,6 +4278,8 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
"nvim",
};
+ // XXX: eval_has_provider() may shell out :(
+ const int save_shell_error = get_vim_var_nr(VV_SHELL_ERROR);
bool n = false;
const char *const name = tv_get_string(&argvars[0]);
for (size_t i = 0; i < ARRAY_SIZE(has_list); i++) {
@@ -4334,6 +4336,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
n = true;
}
+ set_vim_var_nr(VV_SHELL_ERROR, save_shell_error);
rettv->vval.v_number = n;
}
diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua
@@ -68,4 +68,11 @@ describe('has()', function()
eq(0, funcs.has('wsl'))
end
end)
+
+ it('does not change v:shell_error', function()
+ local nvim_prog = helpers.nvim_prog
+ funcs.system({nvim_prog, '-es', '+73cquit'})
+ funcs.has('python3') -- use a call whose implementation shells out
+ eq(73, funcs.eval('v:shell_error'))
+ end)
end)