To: vim_dev@googlegroups.com Subject: Patch 8.2.3852 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3852 Problem: Vim9: not enough tests. Solution: Also run existing tests for Vim9 script. Make errors more consistent. Files: src/testdir/test_listdict.vim, src/eval.c, src/vim9compile.c, src/errors.h *** ../vim-8.2.3851/src/testdir/test_listdict.vim 2021-12-19 10:35:10.700109727 +0000 --- src/testdir/test_listdict.vim 2021-12-19 15:15:22.665883964 +0000 *************** *** 1291,1302 **** " List and dict indexing tests func Test_listdict_index() ! call assert_fails('echo function("min")[0]', 'E695:') ! call assert_fails('echo v:true[0]', 'E909:') let d = {'k' : 10} call assert_fails('echo d.', 'E15:') ! call assert_fails('echo d[1:2]', 'E719:') call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') call assert_fails("let v = range(5)[2:[]]", 'E730:') call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:']) call assert_fails("let v = range(5)[2:3", 'E111:') --- 1291,1309 ---- " List and dict indexing tests func Test_listdict_index() ! call CheckLegacyAndVim9Failure(['echo function("min")[0]'], 'E695:') ! call CheckLegacyAndVim9Failure(['echo v:true[0]'], 'E909:') ! call CheckLegacyAndVim9Failure(['echo v:null[0]'], 'E909:') ! let d = {'k' : 10} call assert_fails('echo d.', 'E15:') ! call CheckDefAndScriptFailure2(['var d = {k: 10}', 'echo d.'], 'E1127', 'E15:') ! ! call CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d[1 : 2]'], 'E719:') ! call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') + call CheckDefAndScriptFailure2(['var v = [4, 6][() => 1]'], 'E1012', 'E703:') + call assert_fails("let v = range(5)[2:[]]", 'E730:') call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:']) call assert_fails("let v = range(5)[2:3", 'E111:') *** ../vim-8.2.3851/src/eval.c 2021-12-19 11:06:19.666495254 +0000 --- src/eval.c 2021-12-19 15:14:31.625891394 +0000 *************** *** 4026,4031 **** --- 4026,4033 ---- } else if (evaluate) { + int error = FALSE; + #ifdef FEAT_FLOAT // allow for indexing with float if (vim9 && rettv->v_type == VAR_DICT *************** *** 4035,4041 **** var1.v_type = VAR_STRING; } #endif ! if (tv_get_string_chk(&var1) == NULL) { // not a number or string clear_tv(&var1); --- 4037,4047 ---- var1.v_type = VAR_STRING; } #endif ! if (vim9 && rettv->v_type == VAR_LIST) ! tv_get_number_chk(&var1, &error); ! else ! error = tv_get_string_chk(&var1) == NULL; ! if (error) { // not a number or string clear_tv(&var1); *************** *** 4118,4124 **** case VAR_FUNC: case VAR_PARTIAL: if (verbose) ! emsg(_("E695: Cannot index a Funcref")); return FAIL; case VAR_FLOAT: #ifdef FEAT_FLOAT --- 4124,4130 ---- case VAR_FUNC: case VAR_PARTIAL: if (verbose) ! emsg(_(e_cannot_index_a_funcref)); return FAIL; case VAR_FLOAT: #ifdef FEAT_FLOAT *** ../vim-8.2.3851/src/vim9compile.c 2021-12-18 12:31:30.619693398 +0000 --- src/vim9compile.c 2021-12-19 14:56:24.748392970 +0000 *************** *** 3043,3049 **** } else { ! emsg(_(e_string_list_dict_or_blob_required)); return FAIL; } return OK; --- 3043,3067 ---- } else { ! switch (vartype) ! { ! case VAR_FUNC: ! case VAR_PARTIAL: ! emsg(_(e_cannot_index_a_funcref)); ! break; ! case VAR_BOOL: ! case VAR_SPECIAL: ! case VAR_JOB: ! case VAR_CHANNEL: ! case VAR_INSTR: ! case VAR_UNKNOWN: ! case VAR_ANY: ! case VAR_VOID: ! emsg(_(e_cannot_index_special_variable)); ! break; ! default: ! emsg(_(e_string_list_dict_or_blob_required)); ! } return FAIL; } return OK; *** ../vim-8.2.3851/src/errors.h 2021-12-18 18:33:41.091346417 +0000 --- src/errors.h 2021-12-19 14:50:41.242305613 +0000 *************** *** 286,291 **** --- 286,293 ---- #ifdef FEAT_EVAL EXTERN char e_invalid_command_str[] INIT(= N_("E476: Invalid command: %s")); + EXTERN char e_cannot_index_a_funcref[] + INIT(= N_("E695: Cannot index a Funcref")); EXTERN char e_list_value_has_more_items_than_targets[] INIT(= N_("E710: List value has more items than targets")); EXTERN char e_list_value_does_not_have_enough_items[] *** ../vim-8.2.3851/src/version.c 2021-12-19 12:32:54.066426460 +0000 --- src/version.c 2021-12-19 15:16:33.209869122 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3852, /**/ -- hundred-and-one symptoms of being an internet addict: 78. You find yourself dialing IP numbers on the phone. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///