summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2024-04-15 19:19:52 +0200
committerChristian Brabandt <cb@256bit.org>2024-04-15 19:19:52 +0200
commitbce51d9005dd1c5bc002acbac2e12b649abcb013 (patch)
tree046a2767183c0fd9eff9249fd44ed676db906de3 /src/eval.c
parenta59e031aa0bdc5cc3d1f4ed719126bf1a1b858ce (diff)
patch 9.1.0335: String interpolation fails for List typev9.1.0335
Problem: String interpolation fails for List type Solution: use implicit string(list) for string interpolation and :put = (Yegappan Lakshmanan) related: #14529 closes: #14556 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/eval.c b/src/eval.c
index d81ef17526..51ee604319 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -575,17 +575,16 @@ skip_expr_concatenate(
/*
* Convert "tv" to a string.
- * When "convert" is TRUE convert a List into a sequence of lines and a Dict
- * into a textual representation of the Dict.
+ * When "join_list" is TRUE convert a List into a sequence of lines.
* Returns an allocated string (NULL when out of memory).
*/
char_u *
-typval2string(typval_T *tv, int convert)
+typval2string(typval_T *tv, int join_list)
{
garray_T ga;
char_u *retval;
- if (convert && tv->v_type == VAR_LIST)
+ if (join_list && tv->v_type == VAR_LIST)
{
ga_init2(&ga, sizeof(char), 80);
if (tv->vval.v_list != NULL)
@@ -597,8 +596,16 @@ typval2string(typval_T *tv, int convert)
ga_append(&ga, NUL);
retval = (char_u *)ga.ga_data;
}
- else if (convert && tv->v_type == VAR_DICT)
- retval = dict2string(tv, get_copyID(), FALSE);
+ else if (tv->v_type == VAR_LIST || tv->v_type == VAR_DICT)
+ {
+ char_u *tofree;
+ char_u numbuf[NUMBUFLEN];
+
+ retval = tv2string(tv, &tofree, numbuf, 0);
+ // Make a copy if we have a value but it's not in allocated memory.
+ if (retval != NULL && tofree == NULL)
+ retval = vim_strsave(retval);
+ }
else
retval = vim_strsave(tv_get_string(tv));
return retval;
@@ -607,13 +614,13 @@ typval2string(typval_T *tv, int convert)
/*
* Top level evaluation function, returning a string. Does not handle line
* breaks.
- * When "convert" is TRUE convert a List into a sequence of lines.
+ * When "join_list" is TRUE convert a List into a sequence of lines.
* Return pointer to allocated memory, or NULL for failure.
*/
char_u *
eval_to_string_eap(
char_u *arg,
- int convert,
+ int join_list,
exarg_T *eap,
int use_simple_function)
{
@@ -631,7 +638,7 @@ eval_to_string_eap(
retval = NULL;
else
{
- retval = typval2string(&tv, convert);
+ retval = typval2string(&tv, join_list);
clear_tv(&tv);
}
clear_evalarg(&evalarg, NULL);
@@ -642,10 +649,10 @@ eval_to_string_eap(
char_u *
eval_to_string(
char_u *arg,
- int convert,
+ int join_list,
int use_simple_function)
{
- return eval_to_string_eap(arg, convert, NULL, use_simple_function);
+ return eval_to_string_eap(arg, join_list, NULL, use_simple_function);
}
/*