To: vim_dev@googlegroups.com Subject: Patch 8.2.1306 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1306 Problem: Checking for first character of dict key is inconsistent. Solution: Add eval_isdictc(). (closes #6546) Files: src/eval.c, src/proto/eval.pro, src/vim9compile.c, src/testdir/test_listdict.vim, src/testdir/test_vim9_expr.vim, src/testdir/test_let.vim *** ../vim-8.2.1305/src/eval.c 2020-07-23 17:16:15.046100627 +0200 --- src/eval.c 2020-07-27 21:37:44.767812499 +0200 *************** *** 3464,3470 **** * dict.name */ key = *arg + 1; ! for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) ; if (len == 0) return FAIL; --- 3464,3470 ---- * dict.name */ key = *arg + 1; ! for (len = 0; eval_isdictc(key[len]); ++len) ; if (len == 0) return FAIL; *************** *** 4997,5003 **** && (eval_isnamec(*p) || (*p == '{' && !vim9script) || ((flags & FNE_INCL_BR) && (*p == '[' ! || (*p == '.' && eval_isnamec1(p[1])))) || mb_nest != 0 || br_nest != 0); MB_PTR_ADV(p)) { --- 4997,5003 ---- && (eval_isnamec(*p) || (*p == '{' && !vim9script) || ((flags & FNE_INCL_BR) && (*p == '[' ! || (*p == '.' && eval_isdictc(p[1])))) || mb_nest != 0 || br_nest != 0); MB_PTR_ADV(p)) { *************** *** 5128,5134 **** int eval_isnamec(int c) { ! return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); } /* --- 5128,5134 ---- int eval_isnamec(int c) { ! return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR; } /* *************** *** 5138,5144 **** int eval_isnamec1(int c) { ! return (ASCII_ISALPHA(c) || c == '_'); } /* --- 5138,5154 ---- int eval_isnamec1(int c) { ! return ASCII_ISALPHA(c) || c == '_'; ! } ! ! /* ! * Return TRUE if character "c" can be used as the first character of a ! * dictionary key. ! */ ! int ! eval_isdictc(int c) ! { ! return ASCII_ISALNUM(c) || c == '_'; } /* *************** *** 5171,5178 **** // the next line then consume the line break. p = eval_next_non_blank(*arg, evalarg, &getnext); if (getnext ! && ((rettv->v_type == VAR_DICT && *p == '.' ! && ASCII_ISALPHA(p[1])) || (*p == '-' && p[1] == '>' && (p[2] == '{' || ASCII_ISALPHA(p[2]))))) { --- 5181,5187 ---- // the next line then consume the line break. p = eval_next_non_blank(*arg, evalarg, &getnext); if (getnext ! && ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1])) || (*p == '-' && p[1] == '>' && (p[2] == '{' || ASCII_ISALPHA(p[2]))))) { *** ../vim-8.2.1305/src/proto/eval.pro 2020-07-08 22:01:43.796114663 +0200 --- src/proto/eval.pro 2020-07-27 20:58:44.233916061 +0200 *************** *** 58,63 **** --- 58,64 ---- char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end, int flags); int eval_isnamec(int c); int eval_isnamec1(int c); + int eval_isdictc(int c); int handle_subscript(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int verbose); int item_copy(typval_T *from, typval_T *to, int deep, int copyID); void echo_one(typval_T *rettv, int with_space, int *atstart, int *needclr); *** ../vim-8.2.1305/src/vim9compile.c 2020-07-26 18:33:05.869028796 +0200 --- src/vim9compile.c 2020-07-27 21:35:54.268433630 +0200 *************** *** 3758,3764 **** if (next != NULL && ((next[0] == '-' && next[1] == '>' && (next[2] == '{' || ASCII_ISALPHA(next[2]))) ! || (next[0] == '.' && ASCII_ISALPHA(next[1])))) { next = next_line_from_context(cctx, TRUE); if (next == NULL) --- 3758,3764 ---- if (next != NULL && ((next[0] == '-' && next[1] == '>' && (next[2] == '{' || ASCII_ISALPHA(next[2]))) ! || (next[0] == '.' && eval_isdictc(next[1])))) { next = next_line_from_context(cctx, TRUE); if (next == NULL) *************** *** 3922,3928 **** return FAIL; // dictionary member: dict.name p = *arg; ! if (eval_isnamec1(*p)) while (eval_isnamec(*p)) MB_PTR_ADV(p); if (p == *arg) --- 3922,3928 ---- return FAIL; // dictionary member: dict.name p = *arg; ! if (eval_isdictc(*p)) while (eval_isnamec(*p)) MB_PTR_ADV(p); if (p == *arg) *** ../vim-8.2.1305/src/testdir/test_listdict.vim 2020-07-11 22:14:54.314422214 +0200 --- src/testdir/test_listdict.vim 2020-07-27 21:01:13.217261308 +0200 *************** *** 282,287 **** --- 282,294 ---- call assert_equal('xxx3', Fn('xxx')) endfunc + func Test_dict_assign() + let d = {} + let d.1 = 1 + let d._ = 2 + call assert_equal({'1': 1, '_': 2}, d) + endfunc + " Function in script-local List or Dict func Test_script_local_dict_func() let g:dict = {} *** ../vim-8.2.1305/src/testdir/test_vim9_expr.vim 2020-07-23 19:06:18.874925878 +0200 --- src/testdir/test_vim9_expr.vim 2020-07-27 21:34:55.136769826 +0200 *************** *** 1310,1315 **** --- 1310,1320 ---- ]) assert_equal(1, d .one) + d = {'1': 1, '_': 2} + assert_equal(1, d + .1) + assert_equal(2, d + ._) # getting the one member should clear the dict after getting the item assert_equal('one', #{one: 'one'}.one) *************** *** 1330,1339 **** vim9script let d = #{one: 'one', ! two: 'two'} assert_equal('one', d.one) assert_equal('one', d .one) assert_equal('one', d[ 'one' ]) --- 1335,1350 ---- vim9script let d = #{one: 'one', ! two: 'two', ! 1: 1, ! _: 2} assert_equal('one', d.one) assert_equal('one', d .one) + assert_equal(1, d + .1) + assert_equal(2, d + ._) assert_equal('one', d[ 'one' ]) *** ../vim-8.2.1305/src/testdir/test_let.vim 2020-07-23 13:11:33.251754387 +0200 --- src/testdir/test_let.vim 2020-07-27 21:41:57.518417813 +0200 *************** *** 293,299 **** let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') ! call assert_fails('let {s}.1 = 2', 'E15:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') --- 293,299 ---- let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') ! call assert_fails('let {s}.1 = 2', 'E18:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') *** ../vim-8.2.1305/src/version.c 2020-07-27 20:02:21.008597321 +0200 --- src/version.c 2020-07-27 21:01:32.829175553 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1306, /**/ -- From "know your smileys": (:-# Said something he shouldn't have /// 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 ///