diff src/dict.c @ 23072:4b398a229b0b v8.2.2082

patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax Commit: https://github.com/vim/vim/commit/e0de171ecd2ff7acd56deda2cf81f0d13a69c803 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 2 17:36:54 2020 +0100 patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax Problem: Vim9: can still use the depricated #{} dict syntax. Solution: Remove support for #{} in Vim9 script. (closes https://github.com/vim/vim/issues/7406, closes https://github.com/vim/vim/issues/7405)
author Bram Moolenaar <Bram@vim.org>
date Wed, 02 Dec 2020 17:45:05 +0100
parents 5b2f97d10a8c
children 285cde4b8d0e
line wrap: on
line diff
--- a/src/dict.c
+++ b/src/dict.c
@@ -783,19 +783,30 @@ dict2string(typval_T *tv, int copyID, in
 }
 
 /*
+ * Advance over a literal key, including "-".  If the first character is not a
+ * literal key character then "key" is returned.
+ */
+    char_u *
+skip_literal_key(char_u *key)
+{
+    char_u *p;
+
+    for (p = key; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p)
+	;
+    return p;
+}
+
+/*
  * Get the key for #{key: val} into "tv" and advance "arg".
  * Return FAIL when there is no valid key.
  */
     static int
 get_literal_key(char_u **arg, typval_T *tv)
 {
-    char_u *p;
+    char_u *p = skip_literal_key(*arg);
 
-    if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-')
+    if (p == *arg)
 	return FAIL;
-
-    for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p)
-	;
     tv->v_type = VAR_STRING;
     tv->vval.v_string = vim_strnsave(*arg, p - *arg);
 
@@ -851,17 +862,15 @@ eval_dict(char_u **arg, typval_T *rettv,
     *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
     while (**arg != '}' && **arg != NUL)
     {
-	char_u *p = to_name_end(*arg, FALSE);
+	int	has_bracket = vim9script && **arg == '[';
 
-	if (literal || (vim9script && *p == ':'))
+	if (literal || (vim9script && !has_bracket))
 	{
 	    if (get_literal_key(arg, &tvkey) == FAIL)
 		goto failret;
 	}
 	else
 	{
-	    int		has_bracket = vim9script && **arg == '[';
-
 	    if (has_bracket)
 		*arg = skipwhite(*arg + 1);
 	    if (eval1(arg, &tvkey, evalarg) == FAIL)	// recursive!