0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 8.2.1861: Vim9: no specific error when parsing lambda fails

Problem:    Vim9: no specific error when parsing lambda fails.
Solution:   Also give syntax errors when not evaluating. (closes #7154)
This commit is contained in:
Bram Moolenaar
2020-10-18 18:03:17 +02:00
parent 335e671322
commit a2c026d0fd
3 changed files with 20 additions and 19 deletions

View File

@@ -860,13 +860,10 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
*arg = skipwhite(*arg); *arg = skipwhite(*arg);
if (**arg != ':') if (**arg != ':')
{ {
if (evaluate) if (*skipwhite(*arg) == ':')
{ semsg(_(e_no_white_space_allowed_before_str), ":");
if (*skipwhite(*arg) == ':') else
semsg(_(e_no_white_space_allowed_before_str), ":"); semsg(_(e_missing_dict_colon), *arg);
else
semsg(_(e_missing_dict_colon), *arg);
}
clear_tv(&tvkey); clear_tv(&tvkey);
goto failret; goto failret;
} }
@@ -899,8 +896,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
item = dict_find(d, key, -1); item = dict_find(d, key, -1);
if (item != NULL) if (item != NULL)
{ {
if (evaluate) semsg(_(e_duplicate_key), key);
semsg(_(e_duplicate_key), key);
clear_tv(&tvkey); clear_tv(&tvkey);
clear_tv(&tv); clear_tv(&tv);
goto failret; goto failret;
@@ -937,21 +933,17 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
break; break;
if (!had_comma) if (!had_comma)
{ {
if (evaluate) if (**arg == ',')
{ semsg(_(e_no_white_space_allowed_before_str), ",");
if (**arg == ',') else
semsg(_(e_no_white_space_allowed_before_str), ","); semsg(_(e_missing_dict_comma), *arg);
else
semsg(_(e_missing_dict_comma), *arg);
}
goto failret; goto failret;
} }
} }
if (**arg != '}') if (**arg != '}')
{ {
if (evaluate) semsg(_(e_missing_dict_end), *arg);
semsg(_(e_missing_dict_end), *arg);
failret: failret:
if (d != NULL) if (d != NULL)
dict_free(d); dict_free(d);

View File

@@ -1805,6 +1805,13 @@ def Test_expr7_lambda()
CheckDefExecFailure(["var s = 'asdf'->{a -> a}('x', 'y')"], CheckDefExecFailure(["var s = 'asdf'->{a -> a}('x', 'y')"],
'E1106: 2 arguments too many') 'E1106: 2 arguments too many')
CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:', 1) CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:', 1)
CheckDefSuccess(['var Fx = {a -> #{k1: 0,', ' k2: 1}}'])
CheckDefFailure(['var Fx = {a -> #{k1: 0', ' k2: 1}}'], 'E722:', 2)
CheckDefFailure(['var Fx = {a -> #{k1: 0,', ' k2 1}}'], 'E720:', 2)
CheckDefSuccess(['var Fx = {a -> [0,', ' 1]}'])
CheckDefFailure(['var Fx = {a -> [0', ' 1]}'], 'E696:', 2)
enddef enddef
def Test_expr7_lambda_vim9script() def Test_expr7_lambda_vim9script()
@@ -2371,7 +2378,7 @@ func Test_expr7_fails()
call CheckDefFailure(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 1) call CheckDefFailure(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 1)
call CheckDefExecFailure(["[1, 2->len()"], 'E697:', 2) call CheckDefExecFailure(["[1, 2->len()"], 'E697:', 2)
call CheckDefExecFailure(["#{a: 1->len()"], 'E488:', 1) call CheckDefExecFailure(["#{a: 1->len()"], 'E722:', 1)
call CheckDefExecFailure(["{'a': 1->len()"], 'E723:', 2) call CheckDefExecFailure(["{'a': 1->len()"], 'E723:', 2)
endfunc endfunc

View File

@@ -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 */
/**/
1861,
/**/ /**/
1860, 1860,
/**/ /**/