changeset 24816:1bed37e82c2e v8.2.2946

patch 8.2.2946: Vim9: substitute expression cannot be a List Commit: https://github.com/vim/vim/commit/2752360646545a9ae4853d2d5ca91cdb07c14eea Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 5 21:36:19 2021 +0200 patch 8.2.2946: Vim9: substitute expression cannot be a List Problem: Vim9: substitute expression cannot be a List in a :def function. Solution: Use typval2string(). (closes https://github.com/vim/vim/issues/8330)
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Jun 2021 21:45:02 +0200
parents a2e03e1f97ea
children cdef49d24454
files src/testdir/test_vim9_cmd.vim src/version.c src/vim9execute.c
diffstat 3 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -1236,6 +1236,13 @@ def Test_substitute_expr()
   END
   CheckScriptSuccess(lines)
   unlet g:cond
+
+  # List results in multiple lines
+  new
+  setline(1, 'some text here')
+  s/text/\=['aaa', 'bbb', 'ccc']/ 
+  assert_equal(['some aaa', 'bbb', 'ccc', ' here'], getline(1, '$'))
+  bwipe!
 enddef
 
 def Test_redir_to_var()
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2946,
+/**/
     2945,
 /**/
     2944,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -4130,7 +4130,7 @@ exe_substitute_instr(void)
     {
 	typval_T *tv = STACK_TV_BOT(-1);
 
-	res = vim_strsave(tv_get_string(tv));
+	res = typval2string(tv, TRUE);
 	--ectx->ec_stack.ga_len;
 	clear_tv(tv);
     }