summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-02-26 20:15:18 +0100
committerBram Moolenaar <Bram@vim.org>2020-02-26 20:15:18 +0100
commitb35efa5ed040162f5c988c71dfc1159045e47585 (patch)
treedf4c2a1b3c97337afd1351672c27c0759c3d5bbb
parentad39c094d261109a695aba2c4f19fe336736cc55 (diff)
downloadvim-git-8.2.0322.tar.gz
patch 8.2.0322: Vim9: error checks not testedv8.2.0322
Problem: Vim9: error checks not tested. Solution: Add more test cases. Avoid error for function loaded later.
-rw-r--r--src/evalvars.c4
-rw-r--r--src/testdir/test_vim9_script.vim20
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c13
4 files changed, 27 insertions, 12 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index 894ee287d..227253e1f 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2541,8 +2541,10 @@ find_var_ht(char_u *name, char_u **varname)
return &curtab->tp_vars->dv_hashtab;
if (*name == 'v') // v: variable
return &vimvarht;
- if (current_sctx.sc_version != SCRIPT_VERSION_VIM9)
+ if (get_current_funccal() != NULL
+ && get_current_funccal()->func->uf_dfunc_idx < 0)
{
+ // a: and l: are only used in functions defined with ":function"
if (*name == 'a') // a: function argument
return get_funccal_args_ht();
if (*name == 'l') // l: local function variable
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 3f0773b17..53ee5119c 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -178,6 +178,15 @@ func Test_call_default_args_from_func()
call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
endfunc
+func TakesOneArg(arg)
+ echo a:arg
+endfunc
+
+def Test_call_wrong_arg_count()
+ call CheckDefFailure(['TakesOneArg()'], 'E119:')
+ call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
+enddef
+
" Default arg and varargs
def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
let res = one .. ',' .. two
@@ -194,13 +203,12 @@ def Test_call_def_varargs()
assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
enddef
+def Test_call_func_defined_later()
+ call assert_equal('one', DefinedLater('one'))
+ call assert_fails('call NotDefined("one")', 'E117:')
+enddef
-"def Test_call_func_defined_later()
-" call assert_equal('one', DefineLater('one'))
-" call assert_fails('call NotDefined("one")', 'E99:')
-"enddef
-
-func DefineLater(arg)
+func DefinedLater(arg)
return a:arg
endfunc
diff --git a/src/version.c b/src/version.c
index beceb6da8..258cab24f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 322,
+/**/
321,
/**/
320,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 32d6349e5..35f20c4c7 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1545,7 +1545,8 @@ compile_load_scriptvar(
cctx_T *cctx,
char_u *name, // variable NUL terminated
char_u *start, // start of variable
- char_u **end) // end of variable
+ char_u **end, // end of variable
+ int error) // when TRUE may give error
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
int idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE);
@@ -1606,7 +1607,8 @@ compile_load_scriptvar(
return OK;
}
- semsg(_("E1050: Item not found: %s"), name);
+ if (error)
+ semsg(_("E1050: Item not found: %s"), name);
return FAIL;
}
@@ -1642,7 +1644,7 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
}
else if (**arg == 's')
{
- res = compile_load_scriptvar(cctx, name, NULL, NULL);
+ res = compile_load_scriptvar(cctx, name, NULL, NULL, error);
}
else
{
@@ -1698,7 +1700,7 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
else if (SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
== SCRIPT_VERSION_VIM9)
// in Vim9 script "var" can be script-local.
- res = compile_load_scriptvar(cctx, name, *arg, &end);
+ res = compile_load_scriptvar(cctx, name, *arg, &end, error);
}
}
if (gen_load)
@@ -3465,7 +3467,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
break;
case dest_script:
- compile_load_scriptvar(cctx, name + (name[1] == ':' ? 2 : 0), NULL, NULL);
+ compile_load_scriptvar(cctx,
+ name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE);
break;
case dest_env:
// Include $ in the name here