To: vim_dev@googlegroups.com Subject: Patch 8.2.2687 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2687 Problem: Vim9: cannot use "const" for global variable in :def function. Solution: Do allow using :const for a global variable. (closes #8030) Files: src/vim9compile.c, src/vim9execute.c, src/testdir/test_vim9_assign.vim *** ../vim-8.2.2686/src/vim9compile.c 2021-04-01 12:57:53.539273235 +0200 --- src/vim9compile.c 2021-04-01 19:10:43.355056592 +0200 *************** *** 5752,5758 **** &lhs->lhs_opt_flags, &lhs->lhs_vimvaridx, &lhs->lhs_type, cctx) == FAIL) return FAIL; ! if (lhs->lhs_dest != dest_local) { // Specific kind of variable recognized. declare_error = is_decl; --- 5752,5759 ---- &lhs->lhs_opt_flags, &lhs->lhs_vimvaridx, &lhs->lhs_type, cctx) == FAIL) return FAIL; ! if (lhs->lhs_dest != dest_local ! && cmdidx != CMD_const && cmdidx != CMD_final) { // Specific kind of variable recognized. declare_error = is_decl; *************** *** 6519,6524 **** --- 6520,6526 ---- else { if (is_decl && cmdidx == CMD_const && (lhs.lhs_dest == dest_script + || lhs.lhs_dest == dest_global || lhs.lhs_dest == dest_local)) // ":const var": lock the value, but not referenced variables generate_LOCKCONST(cctx); *** ../vim-8.2.2686/src/vim9execute.c 2021-03-29 22:14:45.604788424 +0200 --- src/vim9execute.c 2021-04-01 19:35:31.278718005 +0200 *************** *** 963,971 **** store_var(char_u *name, typval_T *tv) { funccal_entry_T entry; save_funccal(&entry); ! set_var_const(name, NULL, tv, FALSE, ASSIGN_DECL, 0); restore_funccal(); } --- 963,974 ---- store_var(char_u *name, typval_T *tv) { funccal_entry_T entry; + int flags = ASSIGN_DECL; + if (tv->v_lock) + flags |= ASSIGN_CONST; save_funccal(&entry); ! set_var_const(name, NULL, tv, FALSE, flags, 0); restore_funccal(); } *** ../vim-8.2.2686/src/testdir/test_vim9_assign.vim 2021-03-28 21:14:02.258994195 +0200 --- src/testdir/test_vim9_assign.vim 2021-04-01 19:41:08.601793641 +0200 *************** *** 1277,1282 **** --- 1277,1289 ---- g:FLIST[0] = 22 assert_equal([22], g:FLIST) + def SetGlobalConst() + const g:globConst = 123 + enddef + SetGlobalConst() + assert_equal(123, g:globConst) + assert_true(islocked('g:globConst')) + const w:FOO: number = 46 assert_equal(46, w:FOO) const w:FOOS = 'wfoos' *************** *** 1341,1346 **** --- 1348,1364 ---- lines =<< trim END vim9script + def SetGlobalConst() + const g:globConst = 123 + enddef + SetGlobalConst() + g:globConst = 234 + END + CheckScriptFailure(lines, 'E741: Value is locked: globConst') + unlet g:globConst + + lines =<< trim END + vim9script const cdict: dict = {} def Change() cdict.foo = 'foo' *** ../vim-8.2.2686/src/version.c 2021-04-01 18:46:49.854092770 +0200 --- src/version.c 2021-04-01 19:11:55.498877606 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2687, /**/ -- It was recently discovered that research causes cancer in rats. /// 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 ///