Skip to content

Commit 5c7a299

Browse files
committed
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.
1 parent 4355894 commit 5c7a299

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/eval.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,8 @@ eval0(
22282228
if (!aborting()
22292229
&& did_emsg == did_emsg_before
22302230
&& called_emsg == called_emsg_before
2231-
&& (flags & EVAL_CONSTANT) == 0)
2231+
&& (flags & EVAL_CONSTANT) == 0
2232+
&& (!in_vim9script() || !vim9_bad_comment(p)))
22322233
semsg(_(e_invexpr2), arg);
22332234

22342235
// Some of the expression may not have been consumed. Do not check for
@@ -3362,7 +3363,11 @@ eval7(
33623363
/*
33633364
* Dictionary: #{key: val, key: val}
33643365
*/
3365-
case '#': if (!in_vim9script() && (*arg)[1] == '{')
3366+
case '#': if (in_vim9script())
3367+
{
3368+
ret = vim9_bad_comment(*arg) ? FAIL : NOTDONE;
3369+
}
3370+
else if ((*arg)[1] == '{')
33663371
{
33673372
++*arg;
33683373
ret = eval_dict(arg, rettv, evalarg, TRUE);

src/ex_docmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5234,7 +5234,8 @@ ends_excmd2(char_u *cmd_start UNUSED, char_u *cmd)
52345234
return TRUE;
52355235
#ifdef FEAT_EVAL
52365236
if (in_vim9script())
5237-
return c == '#' && (cmd == cmd_start || VIM_ISWHITE(cmd[-1]));
5237+
return c == '#' && cmd[1] != '{'
5238+
&& (cmd == cmd_start || VIM_ISWHITE(cmd[-1]));
52385239
#endif
52395240
return c == '"';
52405241
}

src/testdir/test_vim9_expr.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,10 +2159,10 @@ def Test_expr7_dict()
21592159
CheckDefAndScriptSuccess(lines)
21602160

21612161
# legacy syntax doesn't work
2162-
CheckDefFailure(["var x = #{key: 8}"], 'E1170:', 1)
2163-
CheckDefFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1)
2164-
CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1)
2165-
CheckDefFailure(["var x = true ? #{a: 1}"], 'E1170:', 1)
2162+
CheckDefAndScriptFailure(["var x = #{key: 8}"], 'E1170:', 1)
2163+
CheckDefAndScriptFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1)
2164+
CheckDefAndScriptFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1)
2165+
CheckDefAndScriptFailure(["var x = true ? #{a: 1}"], 'E1170:', 1)
21662166

21672167
CheckDefFailure(["var x = {a:8}"], 'E1069:', 1)
21682168
CheckDefFailure(["var x = {a : 8}"], 'E1068:', 1)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2628,
753755
/**/
754756
2627,
755757
/**/

0 commit comments

Comments
 (0)