mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Problem: Vim9: Using #{ for a dictionary gives strange errors. Solution: Give an error when using #{ for a comment after a command.
This commit is contained in:
@@ -375,3 +375,5 @@ EXTERN char e_argument_already_declared_in_script_str[]
|
|||||||
INIT(= N_("E1168: Argument already declared in the script: %s"));
|
INIT(= N_("E1168: Argument already declared in the script: %s"));
|
||||||
EXTERN char e_import_as_name_not_supported_here[]
|
EXTERN char e_import_as_name_not_supported_here[]
|
||||||
INIT(= N_("E1169: 'import * as {name}' not supported here"));
|
INIT(= N_("E1169: 'import * as {name}' not supported here"));
|
||||||
|
EXTERN char e_cannot_use_hash_curly_to_start_comment[]
|
||||||
|
INIT(= N_("E1170: 'Cannot use #{ to start a comment"));
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
int in_vim9script(void);
|
int in_vim9script(void);
|
||||||
void ex_vim9script(exarg_T *eap);
|
void ex_vim9script(exarg_T *eap);
|
||||||
int not_in_vim9(exarg_T *eap);
|
int not_in_vim9(exarg_T *eap);
|
||||||
|
int vim9_bad_comment(char_u *p);
|
||||||
int vim9_comment_start(char_u *p);
|
int vim9_comment_start(char_u *p);
|
||||||
void ex_export(exarg_T *eap);
|
void ex_export(exarg_T *eap);
|
||||||
void free_imports_and_script_vars(int sid);
|
void free_imports_and_script_vars(int sid);
|
||||||
|
@@ -2159,8 +2159,10 @@ def Test_expr7_dict()
|
|||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
# legacy syntax doesn't work
|
# legacy syntax doesn't work
|
||||||
CheckDefFailure(["var x = #{key: 8}"], 'E1097:', 3)
|
CheckDefFailure(["var x = #{key: 8}"], 'E1170:', 1)
|
||||||
CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1097:', 3)
|
CheckDefFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1)
|
||||||
|
CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1)
|
||||||
|
CheckDefFailure(["var x = true ? #{a: 1}"], 'E1170:', 1)
|
||||||
|
|
||||||
CheckDefFailure(["var x = {a:8}"], 'E1069:', 1)
|
CheckDefFailure(["var x = {a:8}"], 'E1069:', 1)
|
||||||
CheckDefFailure(["var x = {a : 8}"], 'E1068:', 1)
|
CheckDefFailure(["var x = {a : 8}"], 'E1068:', 1)
|
||||||
|
@@ -2452,7 +2452,7 @@ def Test_while_loop()
|
|||||||
assert_equal('1_3_', result)
|
assert_equal('1_3_', result)
|
||||||
|
|
||||||
var s = ''
|
var s = ''
|
||||||
while s == 'x' #{comment}
|
while s == 'x' # {comment}
|
||||||
endwhile
|
endwhile
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2620,
|
||||||
/**/
|
/**/
|
||||||
2619,
|
2619,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1546,7 +1546,7 @@ generate_FUNCREF(cctx_T *cctx, ufunc_T *ufunc)
|
|||||||
isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx;
|
isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx;
|
||||||
cctx->ctx_has_closure = 1;
|
cctx->ctx_has_closure = 1;
|
||||||
|
|
||||||
// if the referenced function is a closure, it may use items further up in
|
// If the referenced function is a closure, it may use items further up in
|
||||||
// the nested context, including this one.
|
// the nested context, including this one.
|
||||||
if (ufunc->uf_flags & FC_CLOSURE)
|
if (ufunc->uf_flags & FC_CLOSURE)
|
||||||
cctx->ctx_ufunc->uf_flags |= FC_CLOSURE;
|
cctx->ctx_ufunc->uf_flags |= FC_CLOSURE;
|
||||||
@@ -2401,6 +2401,8 @@ peek_next_line_from_context(cctx_T *cctx)
|
|||||||
if (line != NULL)
|
if (line != NULL)
|
||||||
{
|
{
|
||||||
p = skipwhite(line);
|
p = skipwhite(line);
|
||||||
|
if (vim9_bad_comment(p))
|
||||||
|
return NULL;
|
||||||
if (*p != NUL && !vim9_comment_start(p))
|
if (*p != NUL && !vim9_comment_start(p))
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -2465,6 +2467,8 @@ next_line_from_context(cctx_T *cctx, int skip_comment)
|
|||||||
may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
|
may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
|
||||||
{
|
{
|
||||||
*arg = skipwhite(whitep);
|
*arg = skipwhite(whitep);
|
||||||
|
if (vim9_bad_comment(*arg))
|
||||||
|
return FAIL;
|
||||||
if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg)))
|
if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg)))
|
||||||
{
|
{
|
||||||
char_u *next = next_line_from_context(cctx, TRUE);
|
char_u *next = next_line_from_context(cctx, TRUE);
|
||||||
@@ -4277,10 +4281,13 @@ compile_expr7(
|
|||||||
|
|
||||||
if (!eval_isnamec1(**arg))
|
if (!eval_isnamec1(**arg))
|
||||||
{
|
{
|
||||||
if (ends_excmd(*skipwhite(*arg)))
|
if (!vim9_bad_comment(*arg))
|
||||||
semsg(_(e_empty_expression_str), *arg);
|
{
|
||||||
else
|
if (ends_excmd(*skipwhite(*arg)))
|
||||||
semsg(_(e_name_expected_str), *arg);
|
semsg(_(e_empty_expression_str), *arg);
|
||||||
|
else
|
||||||
|
semsg(_(e_name_expected_str), *arg);
|
||||||
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8297,6 +8304,8 @@ compile_def_function(
|
|||||||
semsg(_(e_trailing_arg), line);
|
semsg(_(e_trailing_arg), line);
|
||||||
goto erret;
|
goto erret;
|
||||||
}
|
}
|
||||||
|
else if (line != NULL && vim9_bad_comment(skipwhite(line)))
|
||||||
|
goto erret;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line = next_line_from_context(&cctx, FALSE);
|
line = next_line_from_context(&cctx, FALSE);
|
||||||
|
@@ -113,12 +113,29 @@ not_in_vim9(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return TRUE if "p" points at a "#". Does not check for white space.
|
* Give an error message if "p" points at "#{" and return TRUE.
|
||||||
|
* This avoids that using a legacy style #{} dictionary leads to difficult to
|
||||||
|
* understand errors.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
vim9_bad_comment(char_u *p)
|
||||||
|
{
|
||||||
|
if (p[0] == '#' && p[1] == '{')
|
||||||
|
{
|
||||||
|
emsg(_(e_cannot_use_hash_curly_to_start_comment));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return TRUE if "p" points at a "#" not followed by '{'.
|
||||||
|
* Does not check for white space.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
vim9_comment_start(char_u *p)
|
vim9_comment_start(char_u *p)
|
||||||
{
|
{
|
||||||
return p[0] == '#';
|
return p[0] == '#' && p[1] != '{';
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FEAT_EVAL) || defined(PROTO)
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
||||||
|
Reference in New Issue
Block a user