patch 9.0.0156: giving E1170 only in an expression is confusing
Problem: Giving E1170 only in an expression is confusing.
Solution: Give E1170 for any "#{ comment". (closes #10855)
diff --git a/src/errors.h b/src/errors.h
index 977abbf..3b23c88 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -2984,8 +2984,8 @@
INIT(= N_("E1168: Argument already declared in the script: %s"));
EXTERN char e_expression_too_recursive_str[]
INIT(= N_("E1169: Expression too recursive: %s"));
-EXTERN char e_cannot_use_hash_curly_to_start_comment_in_an_expression[]
- INIT(= N_("E1170: Cannot use #{ to start a comment in an expression"));
+EXTERN char e_cannot_use_hash_curly_to_start_comment[]
+ INIT(= N_("E1170: Cannot use #{ to start a comment"));
EXTERN char e_missing_end_block[]
INIT(= N_("E1171: Missing } after inline function"));
EXTERN char e_cannot_use_default_values_in_lambda[]
diff --git a/src/eval.c b/src/eval.c
index 8dfbb8f..42b883e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2157,8 +2157,6 @@
break;
p = nl;
}
- else if (vim9_bad_comment(p))
- break;
if (*p != NL)
break;
++p; // skip another NL
@@ -2184,10 +2182,7 @@
break;
p = skipwhite(next);
if (*p != NUL && !vim9_comment_start(p))
- {
- (void)vim9_bad_comment(p);
return next;
- }
if (eval_next_line(NULL, evalarg) == NULL)
break;
}
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index fad0bda..d8a7243 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -2842,8 +2842,14 @@
if (eap->nextcmd != NULL)
++eap->nextcmd;
}
- if (vim9script && has_cmdmod(cmod, FALSE))
- *errormsg = _(e_command_modifier_without_command);
+ if (vim9script)
+ {
+ if (has_cmdmod(cmod, FALSE))
+ *errormsg = _(e_command_modifier_without_command);
+ if (eap->cmd[0] == '#' && eap->cmd[1] == '{'
+ && eap->cmd[2] != '{')
+ *errormsg = _(e_cannot_use_hash_curly_to_start_comment);
+ }
return FAIL;
}
if (*eap->cmd == NUL)
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 98a4590..3199ac3 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2668,8 +2668,12 @@
'vim9script',
'# something',
'#something',
- '#{something',
+ '#{{something',
])
+ v9.CheckScriptFailure([
+ 'vim9script',
+ '#{something',
+ ], 'E1170:')
split Xfile
v9.CheckScriptSuccess([
diff --git a/src/version.c b/src/version.c
index b75d722..196f3e6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 156,
+/**/
155,
/**/
154,
diff --git a/src/vim9script.c b/src/vim9script.c
index e3cb992..e9c9b2c 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -176,16 +176,18 @@
}
/*
- * Give an error message if "p" points at "#{" and return TRUE.
+ * Return TRUE if "p" points at "#{", not "#{{".
+ * Give an error message if not done already.
* This avoids that using a legacy style #{} dictionary leads to difficult to
* understand errors.
*/
int
vim9_bad_comment(char_u *p)
{
- if (!did_emsg && p[0] == '#' && p[1] == '{' && p[2] != '{')
+ if (p[0] == '#' && p[1] == '{' && p[2] != '{')
{
- emsg(_(e_cannot_use_hash_curly_to_start_comment_in_an_expression));
+ if (!did_emsg)
+ emsg(_(e_cannot_use_hash_curly_to_start_comment));
return TRUE;
}
return FALSE;
@@ -194,12 +196,13 @@
/*
* Return TRUE if "p" points at a "#" not followed by one '{'.
+ * Gives an error for using "#{", not for "#{{".
* Does not check for white space.
*/
int
vim9_comment_start(char_u *p)
{
- return p[0] == '#' && (p[1] != '{' || p[2] == '{');
+ return p[0] == '#' && !vim9_bad_comment(p);
}
#if defined(FEAT_EVAL) || defined(PROTO)