From 461a7fcfce3cd6414f990037e6468af3b5ccf119 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 22 Dec 2018 13:28:07 +0100 Subject: 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. --- src/eval.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index 1d14e1b0e5..b6463d2e70 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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) { -- cgit v1.2.3