summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-28 17:19:07 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-28 17:19:07 +0200
commitee8580e52e767916e2a95e8ac0732fd8a5ae0651 (patch)
tree7969a3073d33cf09cfce17fc3b500cad1b6a694d
parent6a950581da52b410a74531044aae8f1f8f38a7df (diff)
downloadvim-git-ee8580e52e767916e2a95e8ac0732fd8a5ae0651.tar.gz
patch 8.2.1534: Vim9: type error for argument type is not at call positionv8.2.1534
Problem: Vim9: type error for argument type is not at call position. Solution: Set the context and stack after checking the arguments. (issue #6785)
-rw-r--r--src/testdir/test_vim9_func.vim9
-rw-r--r--src/userfunc.c7
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c11
4 files changed, 19 insertions, 10 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 2c23a0e16..39382f3f7 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -223,6 +223,15 @@ def Test_call_wrong_args()
call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
call CheckDefFailure(['bufnr(xxx)'], 'E1001:')
call CheckScriptFailure(['def Func(Ref: func(s: string))'], 'E475:')
+
+ let lines =<< trim END
+ vim9script
+ def Func(s: string)
+ echo s
+ enddef
+ Func([])
+ END
+ call CheckScriptFailure(lines, 'E1012: type mismatch, expected string but got list<unknown>', 5)
enddef
" Default arg and varargs
diff --git a/src/userfunc.c b/src/userfunc.c
index f3c04b28a..be706bdbb 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1314,17 +1314,10 @@ call_user_func(
if (fp->uf_def_status != UF_NOT_COMPILED)
{
- estack_push_ufunc(fp, 1);
- save_current_sctx = current_sctx;
- current_sctx = fp->uf_script_ctx;
-
// Execute the function, possibly compiling it first.
call_def_function(fp, argcount, argvars, funcexe->partial, rettv);
--depth;
current_funccal = fc->caller;
-
- estack_pop();
- current_sctx = save_current_sctx;
free_funccal(fc);
return;
}
diff --git a/src/version.c b/src/version.c
index e6299f413..21c6a18f2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1534,
+/**/
1533,
/**/
1532,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 53a748e97..05cf5da6f 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -726,7 +726,7 @@ call_def_function(
int idx;
int ret = FAIL;
int defcount = ufunc->uf_args.ga_len - argc;
- int save_sc_version = current_sctx.sc_version;
+ sctx_T save_current_sctx = current_sctx;
int breakcheck_count = 0;
int called_emsg_before = called_emsg;
@@ -867,7 +867,10 @@ call_def_function(
ectx.ec_instr = dfunc->df_instr;
}
+ // Following errors are in the function, not the caller.
// Commands behave like vim9script.
+ estack_push_ufunc(ufunc, 1);
+ current_sctx = ufunc->uf_script_ctx;
current_sctx.sc_version = SCRIPT_VERSION_VIM9;
// Decide where to start execution, handles optional arguments.
@@ -2614,9 +2617,11 @@ failed:
// When failed need to unwind the call stack.
while (ectx.ec_frame_idx != initial_frame_idx)
func_return(&ectx);
-failed_early:
- current_sctx.sc_version = save_sc_version;
+ estack_pop();
+ current_sctx = save_current_sctx;
+
+failed_early:
// Free all local variables, but not arguments.
for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx)
clear_tv(STACK_TV(idx));