diff --git a/src/eval.c b/src/eval.c index f111dc431..efa168eef 100644 --- a/src/eval.c +++ b/src/eval.c @@ -7892,9 +7892,16 @@ set_var( { if (v->di_tv.v_type == VAR_STRING) { - vim_free(v->di_tv.vval.v_string); + VIM_CLEAR(v->di_tv.vval.v_string); if (copy || tv->v_type != VAR_STRING) - v->di_tv.vval.v_string = vim_strsave(tv_get_string(tv)); + { + char_u *val = tv_get_string(tv); + + // Careful: when assigning to v:errmsg and tv_get_string() + // causes an error message the variable will alrady be set. + if (v->di_tv.vval.v_string == NULL) + v->di_tv.vval.v_string = vim_strsave(val); + } else { /* Take over the string to avoid an extra alloc/free. */ diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim index c7b970a2c..f4b35983d 100644 --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -87,3 +87,10 @@ func Test_readfile_binary() bwipe! call delete('XReadfile') endfunc + +func Test_let_errmsg() + call assert_fails('let v:errmsg = []', 'E730:') + let v:errmsg = '' + call assert_fails('let v:errmsg = []', 'E730:') + let v:errmsg = '' +endfunc diff --git a/src/version.c b/src/version.c index dcbf1c282..8706d9868 100644 --- a/src/version.c +++ b/src/version.c @@ -791,6 +791,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 804, /**/ 803, /**/