mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.1.1195: inside try-block: fn body executed with default arg undefined (#32866)
Problem: inside try-block: fn body executed when default arg is
undefined
Solution: When inside a try-block do not execute function body after an
error in evaluating a default argument expression
(Shane Harper).
closes: vim/vim#16865
2d18789aa6
Co-authored-by: Shane Harper <shane@shaneharper.net>
This commit is contained in:
@@ -1246,7 +1246,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett
|
|||||||
int save_did_emsg = did_emsg;
|
int save_did_emsg = did_emsg;
|
||||||
did_emsg = false;
|
did_emsg = false;
|
||||||
|
|
||||||
if (default_arg_err && (fp->uf_flags & FC_ABORT)) {
|
if (default_arg_err && (fp->uf_flags & FC_ABORT || trylevel > 0)) {
|
||||||
did_emsg = true;
|
did_emsg = true;
|
||||||
} else if (islambda) {
|
} else if (islambda) {
|
||||||
char *p = *(char **)fp->uf_lines.ga_data + 7;
|
char *p = *(char **)fp->uf_lines.ga_data + 7;
|
||||||
|
@@ -166,14 +166,35 @@ func Test_default_arg()
|
|||||||
\ execute('func Args2'))
|
\ execute('func Args2'))
|
||||||
|
|
||||||
" Error in default argument expression
|
" Error in default argument expression
|
||||||
let l =<< trim END
|
func! s:f(x = s:undefined)
|
||||||
func F1(x = y)
|
return a:x
|
||||||
return a:x * 2
|
endfunc
|
||||||
endfunc
|
call assert_fails('echo s:f()', ['E121: Undefined variable: s:undefined',
|
||||||
echo F1()
|
\ 'E121: Undefined variable: a:x'])
|
||||||
END
|
|
||||||
let @a = l->join("\n")
|
func! s:f(x = s:undefined) abort
|
||||||
call assert_fails("exe @a", 'E121:')
|
return a:x
|
||||||
|
endfunc
|
||||||
|
const expected_error = 'E121: Undefined variable: s:undefined'
|
||||||
|
" Only one error should be output; execution of the function should be aborted
|
||||||
|
" after the default argument expression error.
|
||||||
|
call assert_fails('echo s:f()', [expected_error, expected_error])
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_default_argument_expression_error_while_inside_of_a_try_block()
|
||||||
|
func! s:f(v = s:undefined_variable)
|
||||||
|
let s:entered_fn_body = 1
|
||||||
|
return a:v
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
unlet! s:entered_fn_body
|
||||||
|
try
|
||||||
|
call s:f()
|
||||||
|
throw "No exception."
|
||||||
|
catch
|
||||||
|
call assert_exception("E121: Undefined variable: s:undefined_variable")
|
||||||
|
endtry
|
||||||
|
call assert_false(exists('s:entered_fn_body'), "exists('s:entered_fn_body')")
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func s:addFoo(lead)
|
func s:addFoo(lead)
|
||||||
|
Reference in New Issue
Block a user