To: vim_dev@googlegroups.com Subject: Patch 8.2.1355 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1355 Problem: Vim9: no error using :let for options and registers. Solution: Give an error. (closes #6568) Files: src/evalvars.c, src/vim9compile.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1354/src/evalvars.c 2020-07-29 21:37:39.793716241 +0200 --- src/evalvars.c 2020-08-02 16:44:44.356427651 +0200 *************** *** 1219,1224 **** --- 1219,1231 ---- int opt_flags; char_u *tofree = NULL; + if (in_vim9script() && (flags & LET_NO_COMMAND) == 0 + && vim_strchr((char_u *)"$@&", *arg) != NULL) + { + vim9_declare_error(arg); + return NULL; + } + // ":let $VAR = expr": Set environment variable. if (*arg == '$') { *************** *** 1227,1237 **** emsg(_("E996: Cannot lock an environment variable")); return NULL; } - if (in_vim9script() && (flags & LET_NO_COMMAND) == 0) - { - vim9_declare_error(arg); - return NULL; - } // Find the end of the name. ++arg; --- 1234,1239 ---- *************** *** 2427,2433 **** else { scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); ! svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + import->imp_var_vals_idx; tv = sv->sv_tv; } --- 2429,2435 ---- else { scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); ! svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + import->imp_var_vals_idx; tv = sv->sv_tv; } *** ../vim-8.2.1354/src/vim9compile.c 2020-08-01 23:22:15.192256533 +0200 --- src/vim9compile.c 2020-08-02 16:52:53.281704784 +0200 *************** *** 5067,5073 **** case 'w': scope = _("window"); break; case 't': scope = _("tab"); break; case 'v': scope = "v:"; break; ! case '$': semsg(_(e_declare_env_var), name); return; default: return; } semsg(_(e_declare_var), scope, name); --- 5067,5078 ---- case 'w': scope = _("window"); break; case 't': scope = _("tab"); break; case 'v': scope = "v:"; break; ! case '$': semsg(_(e_declare_env_var), name); ! return; ! case '&': semsg(_("E1052: Cannot declare an option: %s"), name); ! return; ! case '@': semsg(_("E1066: Cannot declare a register: %s"), name); ! return; default: return; } semsg(_(e_declare_var), scope, name); *************** *** 5229,5234 **** --- 5234,5241 ---- if (cctx->ctx_skip != SKIP_YES) { + int declare_error = FALSE; + if (*var_start == '&') { int cc; *************** *** 5240,5250 **** emsg(_(e_const_option)); goto theend; } ! if (is_decl) ! { ! semsg(_("E1052: Cannot declare an option: %s"), var_start); ! goto theend; ! } p = var_start; p = find_option_end(&p, &opt_flags); if (p == NULL) --- 5247,5253 ---- emsg(_(e_const_option)); goto theend; } ! declare_error = is_decl; p = var_start; p = find_option_end(&p, &opt_flags); if (p == NULL) *************** *** 5272,5282 **** { dest = dest_env; type = &t_string; ! if (is_decl) ! { ! vim9_declare_error(name); ! goto theend; ! } } else if (*var_start == '@') { --- 5275,5281 ---- { dest = dest_env; type = &t_string; ! declare_error = is_decl; } else if (*var_start == '@') { *************** *** 5287,5333 **** } dest = dest_reg; type = &t_string; ! if (is_decl) ! { ! semsg(_("E1066: Cannot declare a register: %s"), name); ! goto theend; ! } } else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0) { dest = dest_global; ! if (is_decl) ! { ! vim9_declare_error(name); ! goto theend; ! } } else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0) { dest = dest_buffer; ! if (is_decl) ! { ! vim9_declare_error(name); ! goto theend; ! } } else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0) { dest = dest_window; ! if (is_decl) ! { ! vim9_declare_error(name); ! goto theend; ! } } else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0) { dest = dest_tab; ! if (is_decl) ! { ! vim9_declare_error(name); ! goto theend; ! } } else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0) { --- 5286,5312 ---- } dest = dest_reg; type = &t_string; ! declare_error = is_decl; } else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0) { dest = dest_global; ! declare_error = is_decl; } else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0) { dest = dest_buffer; ! declare_error = is_decl; } else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0) { dest = dest_window; ! declare_error = is_decl; } else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0) { dest = dest_tab; ! declare_error = is_decl; } else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0) { *************** *** 5346,5356 **** dest = dest_vimvar; vtv = get_vim_var_tv(vimvaridx); type = typval2type_vimvar(vtv, cctx->ctx_type_list); ! if (is_decl) ! { ! vim9_declare_error(name); ! goto theend; ! } } else { --- 5325,5331 ---- dest = dest_vimvar; vtv = get_vim_var_tv(vimvaridx); type = typval2type_vimvar(vtv, cctx->ctx_type_list); ! declare_error = is_decl; } else { *************** *** 5439,5444 **** --- 5414,5425 ---- goto theend; } } + + if (declare_error) + { + vim9_declare_error(name); + goto theend; + } } // handle "a:name" as a name, not index "name" on "a" *** ../vim-8.2.1354/src/testdir/test_vim9_script.vim 2020-08-01 22:23:17.387734905 +0200 --- src/testdir/test_vim9_script.vim 2020-08-02 16:57:34.724192217 +0200 *************** *** 463,475 **** '[x, y; z] = [1]'], 'E1093:') call CheckDefFailure(['let somevar'], "E1022:") ! call CheckDefFailure(['let &option'], 'E1052:') call CheckDefFailure(['&g:option = 5'], 'E113:') call CheckDefFailure(['let $VAR = 5'], 'E1016: Cannot declare an environment variable:') call CheckDefFailure(['let @~ = 5'], 'E354:') call CheckDefFailure(['let @a = 5'], 'E1066:') call CheckDefFailure(['let g:var = 5'], 'E1016: Cannot declare a global variable:') call CheckDefFailure(['let w:var = 5'], 'E1016: Cannot declare a window variable:') --- 463,478 ---- '[x, y; z] = [1]'], 'E1093:') call CheckDefFailure(['let somevar'], "E1022:") ! call CheckDefFailure(['let &tabstop = 4'], 'E1052:') call CheckDefFailure(['&g:option = 5'], 'E113:') + call CheckScriptFailure(['vim9script', 'let &tabstop = 4'], 'E1052:') call CheckDefFailure(['let $VAR = 5'], 'E1016: Cannot declare an environment variable:') + call CheckScriptFailure(['vim9script', 'let $ENV = "xxx"'], 'E1016:') call CheckDefFailure(['let @~ = 5'], 'E354:') call CheckDefFailure(['let @a = 5'], 'E1066:') + call CheckScriptFailure(['vim9script', 'let @a = "abc"'], 'E1066:') call CheckDefFailure(['let g:var = 5'], 'E1016: Cannot declare a global variable:') call CheckDefFailure(['let w:var = 5'], 'E1016: Cannot declare a window variable:') *** ../vim-8.2.1354/src/version.c 2020-08-02 16:10:02.359921876 +0200 --- src/version.c 2020-08-02 16:57:51.580102359 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1355, /**/ -- hundred-and-one symptoms of being an internet addict: 110. You actually volunteer to become your employer's webmaster. /// 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 ///