• R/O
  • SSH

vim: 提交

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

修訂48e71f9483605f2f51fa3abe32ef05c56c83d6fb (tree)
時間2020-02-27 04:30:09
作者Bram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0322: Vim9: error checks not tested

Commit: https://github.com/vim/vim/commit/b35efa5ed040162f5c988c71dfc1159045e47585
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 26 20:15:18 2020 +0100

patch 8.2.0322: Vim9: error checks not tested
Problem: Vim9: error checks not tested.
Solution: Add more test cases. Avoid error for function loaded later.

Change Summary

差異

diff -r 6f350fb85612 -r 48e71f948360 src/evalvars.c
--- a/src/evalvars.c Wed Feb 26 18:30:04 2020 +0100
+++ b/src/evalvars.c Wed Feb 26 20:30:09 2020 +0100
@@ -2541,8 +2541,10 @@
25412541 return &curtab->tp_vars->dv_hashtab;
25422542 if (*name == 'v') // v: variable
25432543 return &vimvarht;
2544- if (current_sctx.sc_version != SCRIPT_VERSION_VIM9)
2544+ if (get_current_funccal() != NULL
2545+ && get_current_funccal()->func->uf_dfunc_idx < 0)
25452546 {
2547+ // a: and l: are only used in functions defined with ":function"
25462548 if (*name == 'a') // a: function argument
25472549 return get_funccal_args_ht();
25482550 if (*name == 'l') // l: local function variable
diff -r 6f350fb85612 -r 48e71f948360 src/testdir/test_vim9_script.vim
--- a/src/testdir/test_vim9_script.vim Wed Feb 26 18:30:04 2020 +0100
+++ b/src/testdir/test_vim9_script.vim Wed Feb 26 20:30:09 2020 +0100
@@ -178,6 +178,15 @@
178178 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
179179 endfunc
180180
181+func TakesOneArg(arg)
182+ echo a:arg
183+endfunc
184+
185+def Test_call_wrong_arg_count()
186+ call CheckDefFailure(['TakesOneArg()'], 'E119:')
187+ call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
188+enddef
189+
181190 " Default arg and varargs
182191 def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
183192 let res = one .. ',' .. two
@@ -194,13 +203,12 @@
194203 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
195204 enddef
196205
206+def Test_call_func_defined_later()
207+ call assert_equal('one', DefinedLater('one'))
208+ call assert_fails('call NotDefined("one")', 'E117:')
209+enddef
197210
198-"def Test_call_func_defined_later()
199-" call assert_equal('one', DefineLater('one'))
200-" call assert_fails('call NotDefined("one")', 'E99:')
201-"enddef
202-
203-func DefineLater(arg)
211+func DefinedLater(arg)
204212 return a:arg
205213 endfunc
206214
diff -r 6f350fb85612 -r 48e71f948360 src/version.c
--- a/src/version.c Wed Feb 26 18:30:04 2020 +0100
+++ b/src/version.c Wed Feb 26 20:30:09 2020 +0100
@@ -739,6 +739,8 @@
739739 static int included_patches[] =
740740 { /* Add new patch number below this line */
741741 /**/
742+ 322,
743+/**/
742744 321,
743745 /**/
744746 320,
diff -r 6f350fb85612 -r 48e71f948360 src/vim9compile.c
--- a/src/vim9compile.c Wed Feb 26 18:30:04 2020 +0100
+++ b/src/vim9compile.c Wed Feb 26 20:30:09 2020 +0100
@@ -1545,7 +1545,8 @@
15451545 cctx_T *cctx,
15461546 char_u *name, // variable NUL terminated
15471547 char_u *start, // start of variable
1548- char_u **end) // end of variable
1548+ char_u **end, // end of variable
1549+ int error) // when TRUE may give error
15491550 {
15501551 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
15511552 int idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE);
@@ -1606,7 +1607,8 @@
16061607 return OK;
16071608 }
16081609
1609- semsg(_("E1050: Item not found: %s"), name);
1610+ if (error)
1611+ semsg(_("E1050: Item not found: %s"), name);
16101612 return FAIL;
16111613 }
16121614
@@ -1642,7 +1644,7 @@
16421644 }
16431645 else if (**arg == 's')
16441646 {
1645- res = compile_load_scriptvar(cctx, name, NULL, NULL);
1647+ res = compile_load_scriptvar(cctx, name, NULL, NULL, error);
16461648 }
16471649 else
16481650 {
@@ -1698,7 +1700,7 @@
16981700 else if (SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
16991701 == SCRIPT_VERSION_VIM9)
17001702 // in Vim9 script "var" can be script-local.
1701- res = compile_load_scriptvar(cctx, name, *arg, &end);
1703+ res = compile_load_scriptvar(cctx, name, *arg, &end, error);
17021704 }
17031705 }
17041706 if (gen_load)
@@ -3465,7 +3467,8 @@
34653467 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
34663468 break;
34673469 case dest_script:
3468- compile_load_scriptvar(cctx, name + (name[1] == ':' ? 2 : 0), NULL, NULL);
3470+ compile_load_scriptvar(cctx,
3471+ name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE);
34693472 break;
34703473 case dest_env:
34713474 // Include $ in the name here
Show on old repository browser