To: vim_dev@googlegroups.com Subject: Patch 8.2.0322 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0322 Problem: Vim9: error checks not tested. Solution: Add more test cases. Avoid error for function loaded later. Files: src/vim9compile.c, src/evalvars.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.0321/src/vim9compile.c 2020-02-26 18:23:39.558650843 +0100 --- src/vim9compile.c 2020-02-26 19:46:25.307137166 +0100 *************** *** 1545,1551 **** cctx_T *cctx, char_u *name, // variable NUL terminated char_u *start, // start of variable ! char_u **end) // end of variable { scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); int idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE); --- 1545,1552 ---- cctx_T *cctx, char_u *name, // variable NUL terminated char_u *start, // start 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,1612 **** return OK; } ! semsg(_("E1050: Item not found: %s"), name); return FAIL; } --- 1607,1614 ---- return OK; } ! if (error) ! semsg(_("E1050: Item not found: %s"), name); return FAIL; } *************** *** 1642,1648 **** } else if (**arg == 's') { ! res = compile_load_scriptvar(cctx, name, NULL, NULL); } else { --- 1644,1650 ---- } else if (**arg == 's') { ! res = compile_load_scriptvar(cctx, name, NULL, NULL, error); } else { *************** *** 1698,1704 **** 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); } } if (gen_load) --- 1700,1706 ---- 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, error); } } if (gen_load) *************** *** 3465,3471 **** generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); break; case dest_script: ! compile_load_scriptvar(cctx, name + (name[1] == ':' ? 2 : 0), NULL, NULL); break; case dest_env: // Include $ in the name here --- 3467,3474 ---- generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); break; case dest_script: ! compile_load_scriptvar(cctx, ! name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE); break; case dest_env: // Include $ in the name here *** ../vim-8.2.0321/src/evalvars.c 2020-02-26 13:43:48.646089639 +0100 --- src/evalvars.c 2020-02-26 20:07:20.949765392 +0100 *************** *** 2541,2548 **** return &curtab->tp_vars->dv_hashtab; if (*name == 'v') // v: variable return &vimvarht; ! if (current_sctx.sc_version != SCRIPT_VERSION_VIM9) { if (*name == 'a') // a: function argument return get_funccal_args_ht(); if (*name == 'l') // l: local function variable --- 2541,2550 ---- return &curtab->tp_vars->dv_hashtab; if (*name == 'v') // v: variable return &vimvarht; ! 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 *** ../vim-8.2.0321/src/testdir/test_vim9_script.vim 2020-02-26 18:23:39.558650843 +0100 --- src/testdir/test_vim9_script.vim 2020-02-26 20:10:17.453119642 +0100 *************** *** 178,183 **** --- 178,192 ---- 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 let res = one .. ',' .. two *************** *** 194,206 **** assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three')) enddef ! "def Test_call_func_defined_later() ! " call assert_equal('one', DefineLater('one')) ! " call assert_fails('call NotDefined("one")', 'E99:') ! "enddef ! ! func DefineLater(arg) return a:arg endfunc --- 203,214 ---- 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 ! func DefinedLater(arg) return a:arg endfunc *** ../vim-8.2.0321/src/version.c 2020-02-26 18:23:39.558650843 +0100 --- src/version.c 2020-02-26 20:11:51.636779057 +0100 *************** *** 740,741 **** --- 740,743 ---- { /* Add new patch number below this line */ + /**/ + 322, /**/ -- I have a watch cat! Just break in and she'll watch. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///