summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-14 22:22:29 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-14 22:22:29 +0100
commitce9d50df07402cb8e196537a9c4505845adecabc (patch)
tree7ddcb9cc9b1195b7a83b8e8757977ca1e4fede87
parentbbee8d5122b159683b3f52eddd0da85fcf1fcbfd (diff)
downloadvim-git-ce9d50df07402cb8e196537a9c4505845adecabc.tar.gz
patch 8.1.0747: map() with a bad expression doesn't give an errorv8.1.0747
Problem: map() with a bad expression doesn't give an error. (Ingo Karkat) Solution: Check for giving an error message. (closes #3800)
-rw-r--r--src/eval.c40
-rw-r--r--src/testdir/test_filter_map.vim5
-rw-r--r--src/version.c2
3 files changed, 35 insertions, 12 deletions
diff --git a/src/eval.c b/src/eval.c
index 4e2b0f11d..4f931a271 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -696,6 +696,30 @@ eval_to_bool(
return (int)retval;
}
+/*
+ * Call eval1() and give an error message if not done at a lower level.
+ */
+ static int
+eval1_emsg(char_u **arg, typval_T *rettv, int evaluate)
+{
+ int ret;
+ int did_emsg_before = did_emsg;
+ int called_emsg_before = called_emsg;
+
+ ret = eval1(arg, rettv, evaluate);
+ if (ret == FAIL)
+ {
+ // Report the invalid expression unless the expression evaluation has
+ // been cancelled due to an aborting error, an interrupt, or an
+ // exception, or we already gave a more specific error.
+ // Also check called_emsg for when using assert_fails().
+ if (!aborting() && did_emsg == did_emsg_before
+ && called_emsg == called_emsg_before)
+ semsg(_(e_invexpr2), arg);
+ }
+ return ret;
+}
+
static int
eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
{
@@ -729,7 +753,7 @@ eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
if (s == NULL)
return FAIL;
s = skipwhite(s);
- if (eval1(&s, rettv, TRUE) == FAIL)
+ if (eval1_emsg(&s, rettv, TRUE) == FAIL)
return FAIL;
if (*s != NUL) /* check for trailing chars after expr */
{
@@ -8464,18 +8488,9 @@ ex_execute(exarg_T *eap)
while (*arg != NUL && *arg != '|' && *arg != '\n')
{
p = arg;
- if (eval1(&arg, &rettv, !eap->skip) == FAIL)
- {
- /*
- * Report the invalid expression unless the expression evaluation
- * has been cancelled due to an aborting error, an interrupt, or an
- * exception.
- */
- if (!aborting() && did_emsg == save_did_emsg)
- semsg(_(e_invexpr2), p);
- ret = FAIL;
+ ret = eval1_emsg(&arg, &rettv, !eap->skip);
+ if (ret == FAIL)
break;
- }
if (!eap->skip)
{
@@ -10758,6 +10773,7 @@ filter_map(typval_T *argvars, typval_T *rettv, int map)
}
else
{
+ // argvars[0].v_type == VAR_LIST
vimvars[VV_KEY].vv_type = VAR_NUMBER;
for (li = l->lv_first; li != NULL; li = nli)
diff --git a/src/testdir/test_filter_map.vim b/src/testdir/test_filter_map.vim
index c8d64ce0a..1dd3a5b29 100644
--- a/src/testdir/test_filter_map.vim
+++ b/src/testdir/test_filter_map.vim
@@ -79,3 +79,8 @@ func Test_filter_map_dict_expr_funcref()
endfunc
call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), function('s:filter4')))
endfunc
+
+func Test_map_fails()
+ call assert_fails('call map([1], "42 +")', 'E15:')
+ call assert_fails('call filter([1], "42 +")', 'E15:')
+endfunc
diff --git a/src/version.c b/src/version.c
index 4b21d288c..c6b9d5f05 100644
--- a/src/version.c
+++ b/src/version.c
@@ -796,6 +796,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 747,
+/**/
746,
/**/
745,