changeset 24174:99bfaa4693db v8.2.2628

patch 8.2.2628: Vim9: #{ can still be used at the script level Commit: https://github.com/vim/vim/commit/5c7a299c1652b28977c30e3e3a5ab93c65e7f7ed Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 20 13:29:38 2021 +0100 patch 8.2.2628: Vim9: #{ can still be used at the script level Problem: Vim9: #{ can still be used at the script level. Solution: Give an error for #{ like in a :def function.
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Mar 2021 13:30:03 +0100
parents c3fe35ea9e83
children 96522ca7aac2
files src/eval.c src/ex_docmd.c src/testdir/test_vim9_expr.vim src/version.c
diffstat 4 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -2228,7 +2228,8 @@ eval0(
 	if (!aborting()
 		&& did_emsg == did_emsg_before
 		&& called_emsg == called_emsg_before
-		&& (flags & EVAL_CONSTANT) == 0)
+		&& (flags & EVAL_CONSTANT) == 0
+		&& (!in_vim9script() || !vim9_bad_comment(p)))
 	    semsg(_(e_invexpr2), arg);
 
 	// Some of the expression may not have been consumed.  Do not check for
@@ -3362,7 +3363,11 @@ eval7(
     /*
      * Dictionary: #{key: val, key: val}
      */
-    case '#':	if (!in_vim9script() && (*arg)[1] == '{')
+    case '#':	if (in_vim9script())
+		{
+		    ret = vim9_bad_comment(*arg) ? FAIL : NOTDONE;
+		}
+		else if ((*arg)[1] == '{')
 		{
 		    ++*arg;
 		    ret = eval_dict(arg, rettv, evalarg, TRUE);
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -5234,7 +5234,8 @@ ends_excmd2(char_u *cmd_start UNUSED, ch
 	return TRUE;
 #ifdef FEAT_EVAL
     if (in_vim9script())
-	return c == '#' && (cmd == cmd_start || VIM_ISWHITE(cmd[-1]));
+	return c == '#' && cmd[1] != '{'
+				 && (cmd == cmd_start || VIM_ISWHITE(cmd[-1]));
 #endif
     return c == '"';
 }
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -2159,10 +2159,10 @@ def Test_expr7_dict()
   CheckDefAndScriptSuccess(lines)
  
   # legacy syntax doesn't work
-  CheckDefFailure(["var x = #{key: 8}"], 'E1170:', 1)
-  CheckDefFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1)
-  CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1)
-  CheckDefFailure(["var x = true ? #{a: 1}"], 'E1170:', 1)
+  CheckDefAndScriptFailure(["var x = #{key: 8}"], 'E1170:', 1)
+  CheckDefAndScriptFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1)
+  CheckDefAndScriptFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1)
+  CheckDefAndScriptFailure(["var x = true ? #{a: 1}"], 'E1170:', 1)
 
   CheckDefFailure(["var x = {a:8}"], 'E1069:', 1)
   CheckDefFailure(["var x = {a : 8}"], 'E1068:', 1)
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2628,
+/**/
     2627,
 /**/
     2626,