diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 15 | ||||
-rw-r--r-- | src/nvim/testdir/test_method.vim | 5 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5c8f90c490..a6becb4765 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4186,7 +4186,7 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv, typval_T base = *rettv; rettv->v_type = VAR_UNKNOWN; - const int ret = get_lambda_tv(arg, rettv, evaluate); + int ret = get_lambda_tv(arg, rettv, evaluate); if (ret == NOTDONE) { return FAIL; } else if (**arg != '(') { @@ -4198,9 +4198,18 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv, } } tv_clear(rettv); - return FAIL; + ret = FAIL; + } else { + ret = call_func_rettv(arg, rettv, evaluate, NULL, &base, NULL); } - return call_func_rettv(arg, rettv, evaluate, NULL, &base, NULL); + + // Clear the funcref afterwards, so that deleting it while + // evaluating the arguments is possible (see test55). + if (evaluate) { + tv_clear(&base); + } + + return ret; } /// Evaluate "->method()". diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim index 5ad1d47e71..7a6e6aa19d 100644 --- a/src/nvim/testdir/test_method.vim +++ b/src/nvim/testdir/test_method.vim @@ -145,6 +145,11 @@ func Test_method_lambda() " todo: lambda accepts more arguments than it consumes " call assert_fails('eval "text"->{x -> x .. " extended"}("more")', 'E99:') + + " Nvim doesn't include test_refcount(). + " let l = [1, 2, 3] + " eval l->{x -> x}() + " call assert_equal(1, test_refcount(l)) endfunc func Test_method_not_supported() |