diff options
-rw-r--r-- | src/nvim/ex_docmd.c | 3 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index bf5a3944e6..90b816bb6f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1711,6 +1711,9 @@ int execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo, bool preview) goto end; } + cstack_T cstack = { .cs_idx = -1 }; + eap->cstack = &cstack; + // Execute the command execute_cmd0(&retv, eap, &errormsg, preview); diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 8bbadda9b0..7287666190 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -4547,5 +4547,24 @@ describe('API', function() ok(luv.now() - start <= 300) end) end) + it(':call with unknown function does not crash #26289', function() + eq('Vim:E117: Unknown function: UnknownFunc', + pcall_err(meths.cmd, {cmd = 'call', args = {'UnknownFunc()'}}, {})) + end) + it(':throw does not crash #24556', function() + eq('42', pcall_err(meths.cmd, {cmd = 'throw', args = {'42'}}, {})) + end) + it('can use :return #24556', function() + exec([[ + func Foo() + let g:pos = 'before' + call nvim_cmd({'cmd': 'return', 'args': ['[1, 2, 3]']}, {}) + let g:pos = 'after' + endfunc + let g:result = Foo() + ]]) + eq('before', meths.get_var('pos')) + eq({1, 2, 3}, meths.get_var('result')) + end) end) end) |