comparison src/vim9compile.c @ 21540:8e278698b1fe v8.2.1320

patch 8.2.1320: Vim9: cannot declare some single letter variables Commit: https://github.com/vim/vim/commit/33afa2447bdb0bdd15253c69a2cf6f9903685815 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jul 29 19:18:00 2020 +0200 patch 8.2.1320: Vim9: cannot declare some single letter variables Problem: Vim9: cannot declare some single letter variables. Solution: Do not recognize a colon for a namespace for single letter variables. (closes #6547)
author Bram Moolenaar <Bram@vim.org>
date Wed, 29 Jul 2020 19:30:04 +0200
parents c7b2ce90c2de
children 4d3e983313dc
comparison
equal deleted inserted replaced
21539:acd256ae2fca 21540:8e278698b1fe
5235 { 5235 {
5236 semsg(_("E1066: Cannot declare a register: %s"), name); 5236 semsg(_("E1066: Cannot declare a register: %s"), name);
5237 goto theend; 5237 goto theend;
5238 } 5238 }
5239 } 5239 }
5240 else if (STRNCMP(var_start, "g:", 2) == 0) 5240 else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0)
5241 { 5241 {
5242 dest = dest_global; 5242 dest = dest_global;
5243 if (is_decl) 5243 if (is_decl)
5244 { 5244 {
5245 vim9_declare_error(name); 5245 vim9_declare_error(name);
5246 goto theend; 5246 goto theend;
5247 } 5247 }
5248 } 5248 }
5249 else if (STRNCMP(var_start, "b:", 2) == 0) 5249 else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0)
5250 { 5250 {
5251 dest = dest_buffer; 5251 dest = dest_buffer;
5252 if (is_decl) 5252 if (is_decl)
5253 { 5253 {
5254 vim9_declare_error(name); 5254 vim9_declare_error(name);
5255 goto theend; 5255 goto theend;
5256 } 5256 }
5257 } 5257 }
5258 else if (STRNCMP(var_start, "w:", 2) == 0) 5258 else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0)
5259 { 5259 {
5260 dest = dest_window; 5260 dest = dest_window;
5261 if (is_decl) 5261 if (is_decl)
5262 { 5262 {
5263 vim9_declare_error(name); 5263 vim9_declare_error(name);
5264 goto theend; 5264 goto theend;
5265 } 5265 }
5266 } 5266 }
5267 else if (STRNCMP(var_start, "t:", 2) == 0) 5267 else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0)
5268 { 5268 {
5269 dest = dest_tab; 5269 dest = dest_tab;
5270 if (is_decl) 5270 if (is_decl)
5271 { 5271 {
5272 vim9_declare_error(name); 5272 vim9_declare_error(name);
5273 goto theend; 5273 goto theend;
5274 } 5274 }
5275 } 5275 }
5276 else if (STRNCMP(var_start, "v:", 2) == 0) 5276 else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0)
5277 { 5277 {
5278 typval_T *vtv; 5278 typval_T *vtv;
5279 int di_flags; 5279 int di_flags;
5280 5280
5281 vimvaridx = find_vim_var(name + 2, &di_flags); 5281 vimvaridx = find_vim_var(name + 2, &di_flags);
5335 semsg(_("E1018: Cannot assign to a constant: %s"), 5335 semsg(_("E1018: Cannot assign to a constant: %s"),
5336 name); 5336 name);
5337 goto theend; 5337 goto theend;
5338 } 5338 }
5339 } 5339 }
5340 else if (STRNCMP(var_start, "s:", 2) == 0 5340 else if ((varlen > 1 && STRNCMP(var_start, "s:", 2) == 0)
5341 || lookup_script(var_start, varlen) == OK 5341 || lookup_script(var_start, varlen) == OK
5342 || find_imported(var_start, varlen, cctx) != NULL) 5342 || find_imported(var_start, varlen, cctx) != NULL)
5343 { 5343 {
5344 dest = dest_script; 5344 dest = dest_script;
5345 if (is_decl) 5345 if (is_decl)
5346 { 5346 {
5347 semsg(_("E1054: Variable already declared in the script: %s"), 5347 if ((varlen > 1 && STRNCMP(var_start, "s:", 2) == 0))
5348 semsg(_("E1101: Cannot declare a script variable in a function: %s"),
5349 name);
5350 else
5351 semsg(_("E1054: Variable already declared in the script: %s"),
5348 name); 5352 name);
5349 goto theend; 5353 goto theend;
5350 } 5354 }
5351 } 5355 }
5352 else if (name[1] == ':' && name[2] != NUL) 5356 else if (name[1] == ':' && name[2] != NUL)