To: vim_dev@googlegroups.com Subject: Patch 8.2.1682 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1682 Problem: Vim9: const works in an unexpected way. Solution: ":const" only disallows changing the variable, not the value. Make "list[0] = 9" work at the script level. Files: src/vim9compile.c, src/evalvars.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1681/src/vim9compile.c 2020-09-14 16:37:30.906845912 +0200 --- src/vim9compile.c 2020-09-14 17:35:43.856273147 +0200 *************** *** 4800,4810 **** semsg(_(e_variable_already_declared), name); goto theend; } - else if (lvar->lv_const) - { - semsg(_(e_cannot_assign_to_constant), name); - goto theend; - } } else { --- 4800,4805 ---- *************** *** 4960,4965 **** --- 4955,4965 ---- semsg(_(e_cannot_assign_to_argument), name); goto theend; } + if (!is_decl && lvar != NULL && lvar->lv_const && !has_index) + { + semsg(_(e_cannot_assign_to_constant), name); + goto theend; + } if (!heredoc) { *** ../vim-8.2.1681/src/evalvars.c 2020-09-12 19:51:39.096297159 +0200 --- src/evalvars.c 2020-09-14 17:58:40.864410462 +0200 *************** *** 2945,2950 **** --- 2945,2951 ---- char_u *varname; hashtab_T *ht; int is_script_local; + int vim9script = in_vim9script(); ht = find_var_ht(name, &varname); if (ht == NULL || *varname == NUL) *************** *** 2954,2960 **** } is_script_local = ht == get_script_local_ht(); ! if (in_vim9script() && !is_script_local && (flags & LET_NO_COMMAND) == 0 && name[1] == ':') --- 2955,2961 ---- } is_script_local = ht == get_script_local_ht(); ! if (vim9script && !is_script_local && (flags & LET_NO_COMMAND) == 0 && name[1] == ':') *************** *** 2992,2998 **** goto failed; } ! if (is_script_local && in_vim9script()) { if ((flags & LET_NO_COMMAND) == 0) { --- 2993,2999 ---- goto failed; } ! if (is_script_local && vim9script) { if ((flags & LET_NO_COMMAND) == 0) { *************** *** 3088,3094 **** if (flags & LET_IS_CONST) di->di_flags |= DI_FLAGS_LOCK; ! if (is_script_local && in_vim9script()) { scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); --- 3089,3095 ---- if (flags & LET_IS_CONST) di->di_flags |= DI_FLAGS_LOCK; ! if (is_script_local && vim9script) { scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); *************** *** 3123,3129 **** init_tv(tv); } ! if (flags & LET_IS_CONST) // Like :lockvar! name: lock the value and what it contains, but only // if the reference count is up to one. That locks only literal // values. --- 3124,3131 ---- init_tv(tv); } ! // ":const var = val" locks the value, but not in Vim9 script ! if ((flags & LET_IS_CONST) && !vim9script) // Like :lockvar! name: lock the value and what it contains, but only // if the reference count is up to one. That locks only literal // values. *** ../vim-8.2.1681/src/testdir/test_vim9_script.vim 2020-09-14 17:04:27.652663882 +0200 --- src/testdir/test_vim9_script.vim 2020-09-14 17:27:32.665553534 +0200 *************** *** 821,828 **** --- 821,835 ---- def Test_const() CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:') CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:') + CheckDefFailure(['const list = [1, 2]', 'let list = [3, 4]'], 'E1017:') CheckDefFailure(['const two'], 'E1021:') CheckDefFailure(['const &option'], 'E996:') + + let lines =<< trim END + const list = [1, 2, 3] + list[0] = 4 + END + CheckDefAndScriptSuccess(lines) enddef def Test_range_no_colon() *** ../vim-8.2.1681/src/version.c 2020-09-14 17:04:27.652663882 +0200 --- src/version.c 2020-09-14 18:14:21.345653198 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1682, /**/ -- Girls are like internet domain names, the ones I like are already taken. Well, you can stil get one from a strange country :-P /// 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 ///