comparison src/vim9compile.c @ 21610:586241ee8096 v8.2.1355

patch 8.2.1355: Vim9: no error using :let for options and registers Commit: https://github.com/vim/vim/commit/c2ee44cc382d4b097f51ea3251f00fb35493ea4f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 2 16:59:00 2020 +0200 patch 8.2.1355: Vim9: no error using :let for options and registers Problem: Vim9: no error using :let for options and registers. Solution: Give an error. (closes https://github.com/vim/vim/issues/6568)
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Aug 2020 17:00:06 +0200
parents d9c45474cac1
children c495d3e30f4b
comparison
equal deleted inserted replaced
21609:5f68185d8148 21610:586241ee8096
5065 case 'g': scope = _("global"); break; 5065 case 'g': scope = _("global"); break;
5066 case 'b': scope = _("buffer"); break; 5066 case 'b': scope = _("buffer"); break;
5067 case 'w': scope = _("window"); break; 5067 case 'w': scope = _("window"); break;
5068 case 't': scope = _("tab"); break; 5068 case 't': scope = _("tab"); break;
5069 case 'v': scope = "v:"; break; 5069 case 'v': scope = "v:"; break;
5070 case '$': semsg(_(e_declare_env_var), name); return; 5070 case '$': semsg(_(e_declare_env_var), name);
5071 return;
5072 case '&': semsg(_("E1052: Cannot declare an option: %s"), name);
5073 return;
5074 case '@': semsg(_("E1066: Cannot declare a register: %s"), name);
5075 return;
5071 default: return; 5076 default: return;
5072 } 5077 }
5073 semsg(_(e_declare_var), scope, name); 5078 semsg(_(e_declare_var), scope, name);
5074 } 5079 }
5075 5080
5227 if (!heredoc) 5232 if (!heredoc)
5228 type = &t_any; 5233 type = &t_any;
5229 5234
5230 if (cctx->ctx_skip != SKIP_YES) 5235 if (cctx->ctx_skip != SKIP_YES)
5231 { 5236 {
5237 int declare_error = FALSE;
5238
5232 if (*var_start == '&') 5239 if (*var_start == '&')
5233 { 5240 {
5234 int cc; 5241 int cc;
5235 long numval; 5242 long numval;
5236 5243
5238 if (cmdidx == CMD_const) 5245 if (cmdidx == CMD_const)
5239 { 5246 {
5240 emsg(_(e_const_option)); 5247 emsg(_(e_const_option));
5241 goto theend; 5248 goto theend;
5242 } 5249 }
5243 if (is_decl) 5250 declare_error = is_decl;
5244 {
5245 semsg(_("E1052: Cannot declare an option: %s"), var_start);
5246 goto theend;
5247 }
5248 p = var_start; 5251 p = var_start;
5249 p = find_option_end(&p, &opt_flags); 5252 p = find_option_end(&p, &opt_flags);
5250 if (p == NULL) 5253 if (p == NULL)
5251 { 5254 {
5252 // cannot happen? 5255 // cannot happen?
5270 } 5273 }
5271 else if (*var_start == '$') 5274 else if (*var_start == '$')
5272 { 5275 {
5273 dest = dest_env; 5276 dest = dest_env;
5274 type = &t_string; 5277 type = &t_string;
5275 if (is_decl) 5278 declare_error = is_decl;
5276 {
5277 vim9_declare_error(name);
5278 goto theend;
5279 }
5280 } 5279 }
5281 else if (*var_start == '@') 5280 else if (*var_start == '@')
5282 { 5281 {
5283 if (!valid_yank_reg(var_start[1], TRUE)) 5282 if (!valid_yank_reg(var_start[1], TRUE))
5284 { 5283 {
5285 emsg_invreg(var_start[1]); 5284 emsg_invreg(var_start[1]);
5286 goto theend; 5285 goto theend;
5287 } 5286 }
5288 dest = dest_reg; 5287 dest = dest_reg;
5289 type = &t_string; 5288 type = &t_string;
5290 if (is_decl) 5289 declare_error = is_decl;
5291 {
5292 semsg(_("E1066: Cannot declare a register: %s"), name);
5293 goto theend;
5294 }
5295 } 5290 }
5296 else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0) 5291 else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0)
5297 { 5292 {
5298 dest = dest_global; 5293 dest = dest_global;
5299 if (is_decl) 5294 declare_error = is_decl;
5300 {
5301 vim9_declare_error(name);
5302 goto theend;
5303 }
5304 } 5295 }
5305 else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0) 5296 else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0)
5306 { 5297 {
5307 dest = dest_buffer; 5298 dest = dest_buffer;
5308 if (is_decl) 5299 declare_error = is_decl;
5309 {
5310 vim9_declare_error(name);
5311 goto theend;
5312 }
5313 } 5300 }
5314 else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0) 5301 else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0)
5315 { 5302 {
5316 dest = dest_window; 5303 dest = dest_window;
5317 if (is_decl) 5304 declare_error = is_decl;
5318 {
5319 vim9_declare_error(name);
5320 goto theend;
5321 }
5322 } 5305 }
5323 else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0) 5306 else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0)
5324 { 5307 {
5325 dest = dest_tab; 5308 dest = dest_tab;
5326 if (is_decl) 5309 declare_error = is_decl;
5327 {
5328 vim9_declare_error(name);
5329 goto theend;
5330 }
5331 } 5310 }
5332 else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0) 5311 else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0)
5333 { 5312 {
5334 typval_T *vtv; 5313 typval_T *vtv;
5335 int di_flags; 5314 int di_flags;
5344 if (var_check_ro(di_flags, name, FALSE)) 5323 if (var_check_ro(di_flags, name, FALSE))
5345 goto theend; 5324 goto theend;
5346 dest = dest_vimvar; 5325 dest = dest_vimvar;
5347 vtv = get_vim_var_tv(vimvaridx); 5326 vtv = get_vim_var_tv(vimvaridx);
5348 type = typval2type_vimvar(vtv, cctx->ctx_type_list); 5327 type = typval2type_vimvar(vtv, cctx->ctx_type_list);
5349 if (is_decl) 5328 declare_error = is_decl;
5350 {
5351 vim9_declare_error(name);
5352 goto theend;
5353 }
5354 } 5329 }
5355 else 5330 else
5356 { 5331 {
5357 int idx; 5332 int idx;
5358 imported_T *import = NULL; 5333 imported_T *import = NULL;
5436 else if (!is_decl) 5411 else if (!is_decl)
5437 { 5412 {
5438 semsg(_("E1089: unknown variable: %s"), name); 5413 semsg(_("E1089: unknown variable: %s"), name);
5439 goto theend; 5414 goto theend;
5440 } 5415 }
5416 }
5417
5418 if (declare_error)
5419 {
5420 vim9_declare_error(name);
5421 goto theend;
5441 } 5422 }
5442 } 5423 }
5443 5424
5444 // handle "a:name" as a name, not index "name" on "a" 5425 // handle "a:name" as a name, not index "name" on "a"
5445 if (varlen > 1 || var_start[varlen] != ':') 5426 if (varlen > 1 || var_start[varlen] != ':')