Patch 8.2.1011

3 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 19, 2020, 12:34:58 PM6/19/20
to vim...@googlegroups.com

Patch 8.2.1011
Problem: Vim9: some code not tested.
Solution: Add a few more test cases. Reorder checks for clearer error.
Remove unreachable code.
Files: src/evalvars.c, src/vim9script.c, src/vim9execute.c,
src/proto/vim9script.pro, src/testdir/test_vim9_script.vim,
src/testdir/test_vim9_expr.vim


*** ../vim-8.2.1010/src/evalvars.c 2020-06-16 20:03:38.747351038 +0200
--- src/evalvars.c 2020-06-19 18:13:24.041375680 +0200
***************
*** 2886,2895 ****
return;
}

- if (var_check_ro(di->di_flags, name, FALSE)
- || var_check_lock(di->di_tv.v_lock, name, FALSE))
- return;
-
if (is_script_local
&& current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
--- 2886,2891 ----
***************
*** 2900,2907 ****
}

// check the type
! check_script_var_type(&di->di_tv, tv, name);
}
}
else
// can only redefine once
--- 2896,2908 ----
}

// check the type
! if (check_script_var_type(&di->di_tv, tv, name) == FAIL)
! return;
}
+
+ if (var_check_ro(di->di_flags, name, FALSE)
+ || var_check_lock(di->di_tv.v_lock, name, FALSE))
+ return;
}
else
// can only redefine once
*** ../vim-8.2.1010/src/vim9script.c 2020-06-16 23:18:48.116416938 +0200
--- src/vim9script.c 2020-06-19 18:14:18.829224485 +0200
***************
*** 507,513 ****
/*
* Check if the type of script variable "dest" allows assigning "value".
*/
! void
check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
--- 507,513 ----
/*
* Check if the type of script variable "dest" allows assigning "value".
*/
! int
check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
***************
*** 521,533 ****
if (sv->sv_tv == dest)
{
if (sv->sv_const)
semsg(_(e_readonlyvar), name);
! else
! check_type(sv->sv_type, typval2type(value), TRUE);
! return;
}
}
iemsg("check_script_var_type(): not found");
}

#endif // FEAT_EVAL
--- 521,535 ----
if (sv->sv_tv == dest)
{
if (sv->sv_const)
+ {
semsg(_(e_readonlyvar), name);
! return FAIL;
! }
! return check_type(sv->sv_type, typval2type(value), TRUE);
}
}
iemsg("check_script_var_type(): not found");
+ return OK; // not really
}

#endif // FEAT_EVAL
*** ../vim-8.2.1010/src/vim9execute.c 2020-06-18 22:43:23.729327368 +0200
--- src/vim9execute.c 2020-06-19 18:33:12.190106467 +0200
***************
*** 2144,2161 ****
listitem_T *li;
int index = iptr->isn_arg.number;

! // get list item: list is at stack-1, push item
tv = STACK_TV_BOT(-1);
! if (tv->v_type != VAR_LIST)
! {
! emsg(_(e_listreq));
! goto failed;
! }
! if ((li = list_find(tv->vval.v_list, index)) == NULL)
! {
! semsg(_(e_listidx), index);
! goto failed;
! }

if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
goto failed;
--- 2144,2153 ----
listitem_T *li;
int index = iptr->isn_arg.number;

! // Get list item: list is at stack-1, push item.
! // List type and length is checked for when compiling.
tv = STACK_TV_BOT(-1);
! li = list_find(tv->vval.v_list, index);

if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
goto failed;
*** ../vim-8.2.1010/src/proto/vim9script.pro 2020-06-13 19:00:06.887160162 +0200
--- src/proto/vim9script.pro 2020-06-19 18:14:24.209209632 +0200
***************
*** 7,11 ****
int find_exported(int sid, char_u **argp, int *name_len, ufunc_T **ufunc, type_T **type);
char_u *handle_import(char_u *arg_start, garray_T *gap, int import_sid, void *cctx);
char_u *vim9_declare_scriptvar(exarg_T *eap, char_u *arg);
! void check_script_var_type(typval_T *dest, typval_T *value, char_u *name);
/* vim: set ft=c : */
--- 7,11 ----
int find_exported(int sid, char_u **argp, int *name_len, ufunc_T **ufunc, type_T **type);
char_u *handle_import(char_u *arg_start, garray_T *gap, int import_sid, void *cctx);
char_u *vim9_declare_scriptvar(exarg_T *eap, char_u *arg);
! int check_script_var_type(typval_T *dest, typval_T *value, char_u *name);
/* vim: set ft=c : */
*** ../vim-8.2.1010/src/testdir/test_vim9_script.vim 2020-06-18 22:43:23.729327368 +0200
--- src/testdir/test_vim9_script.vim 2020-06-19 18:17:41.648665400 +0200
***************
*** 140,145 ****
--- 140,148 ----
let dict4: dict<any> = #{one: 1, two: '2'}
let dict5: dict<blob> = #{one: 0z01, two: 0z02}

+ " overwrite
+ dict3['key'] = 'another'
+
call CheckDefExecFailure(['let dd = {}', 'dd[""] = 6'], 'E713:')

# type becomes dict<any>
***************
*** 219,224 ****
--- 222,234 ----

let thechannel: channel
assert_equal(test_null_channel(), thechannel)
+
+ if has('unix') && executable('cat')
+ " check with non-null job and channel, types must match
+ thejob = job_start("cat ", #{})
+ thechannel = job_getchannel(thejob)
+ job_stop(thejob, 'kill')
+ endif
endif

let nr = 1234 | nr = 5678
***************
*** 775,780 ****
--- 785,793 ----
CheckScriptFailure(['vim9script', 'export let g:some'], 'E1044:')
CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')

+ CheckScriptFailure(['vim9script', 'let str: string', 'str = 1234'], 'E1013:')
+ CheckScriptFailure(['vim9script', 'const str = "asdf"', 'str = "xxx"'], 'E46:')
+
assert_fails('vim9script', 'E1038')
assert_fails('export something', 'E1043')
enddef
*** ../vim-8.2.1010/src/testdir/test_vim9_expr.vim 2020-05-18 13:37:58.558383291 +0200
--- src/testdir/test_vim9_expr.vim 2020-06-19 18:23:28.135711750 +0200
***************
*** 524,529 ****
--- 524,530 ----
g:anint)
assert_equal(9, g:alsoint + 5)
assert_equal(14, g:alsoint + g:anint)
+ assert_equal([1, 2, 3, 4], [1] + g:alist)

assert_equal(54, 60 - 6)
assert_equal(50, 60 -
*** ../vim-8.2.1010/src/version.c 2020-06-19 17:20:38.505781931 +0200
--- src/version.c 2020-06-19 18:33:33.442048119 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1011,
/**/

--
Vi beats Emacs to death, and then again!
http://linuxtoday.com/stories/5764.html

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages