0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict

Problem:    :echomsg and :echoerr do not handle List and Dict like :echo does.
            (Daniel Hahler)
Solution:   Be more tolerant about the expression result type.
This commit is contained in:
Bram Moolenaar
2018-12-22 13:28:07 +01:00
parent 528ccfbaa1
commit 461a7fcfce
8 changed files with 73 additions and 9 deletions

View File

@@ -7162,6 +7162,30 @@ tv_get_string_buf_chk(typval_T *varp, char_u *buf)
return NULL;
}
/*
* Turn a typeval into a string. Similar to tv_get_string_buf() but uses
* string() on Dict, List, etc.
*/
char_u *
tv_stringify(typval_T *varp, char_u *buf)
{
if (varp->v_type == VAR_LIST
|| varp->v_type == VAR_DICT
|| varp->v_type == VAR_FUNC
|| varp->v_type == VAR_PARTIAL
|| varp->v_type == VAR_FLOAT)
{
typval_T tmp;
f_string(varp, &tmp);
tv_get_string_buf(&tmp, buf);
clear_tv(varp);
*varp = tmp;
return tmp.vval.v_string;
}
return tv_get_string_buf(varp, buf);
}
/*
* Find variable "name" in the list of variables.
* Return a pointer to it if found, NULL if not found.
@@ -8142,7 +8166,12 @@ ex_execute(exarg_T *eap)
if (!eap->skip)
{
p = tv_get_string(&rettv);
char_u buf[NUMBUFLEN];
if (eap->cmdidx == CMD_execute)
p = tv_get_string_buf(&rettv, buf);
else
p = tv_stringify(&rettv, buf);
len = (int)STRLEN(p);
if (ga_grow(&ga, len + 2) == FAIL)
{