comparison src/vim9compile.c @ 24717:bf8feac8a89a v8.2.2897

patch 8.2.2897: Vim9: can use reserved words at the script level Commit: https://github.com/vim/vim/commit/d0edaf9dc253e619ccc321ceaac321aee11c1ea5 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 28 21:06:08 2021 +0200 patch 8.2.2897: Vim9: can use reserved words at the script level Problem: Vim9: can use reserved words at the script level. Solution: Check variable names for reserved words. (closes https://github.com/vim/vim/issues/8253)
author Bram Moolenaar <Bram@vim.org>
date Fri, 28 May 2021 21:15:03 +0200
parents 34a5329b85aa
children 7464d4c927f5
comparison
equal deleted inserted replaced
24716:33f991b5be54 24717:bf8feac8a89a
5591 return 2; 5591 return 2;
5592 if (STRNCMP(p, "..=", 3) == 0) 5592 if (STRNCMP(p, "..=", 3) == 0)
5593 return 3; 5593 return 3;
5594 return 0; 5594 return 0;
5595 } 5595 }
5596
5597 // words that cannot be used as a variable
5598 static char *reserved[] = {
5599 "true",
5600 "false",
5601 "null",
5602 NULL
5603 };
5604 5596
5605 /* 5597 /*
5606 * Generate the load instruction for "name". 5598 * Generate the load instruction for "name".
5607 */ 5599 */
5608 static void 5600 static void
5993 // Specific kind of variable recognized. 5985 // Specific kind of variable recognized.
5994 declare_error = is_decl; 5986 declare_error = is_decl;
5995 } 5987 }
5996 else 5988 else
5997 { 5989 {
5998 int idx;
5999
6000 // No specific kind of variable recognized, just a name. 5990 // No specific kind of variable recognized, just a name.
6001 for (idx = 0; reserved[idx] != NULL; ++idx) 5991 if (check_reserved_name(lhs->lhs_name) == FAIL)
6002 if (STRCMP(reserved[idx], lhs->lhs_name) == 0) 5992 return FAIL;
6003 {
6004 semsg(_(e_cannot_use_reserved_name), lhs->lhs_name);
6005 return FAIL;
6006 }
6007
6008 5993
6009 if (lookup_local(var_start, lhs->lhs_varlen, 5994 if (lookup_local(var_start, lhs->lhs_varlen,
6010 &lhs->lhs_local_lvar, cctx) == OK) 5995 &lhs->lhs_local_lvar, cctx) == OK)
6011 lhs->lhs_lvar = &lhs->lhs_local_lvar; 5996 lhs->lhs_lvar = &lhs->lhs_local_lvar;
6012 else 5997 else