Patch 8.2.2356
Problem:    Vim9: ":put =expr" does not handle a list properly.
Solution:   Use the same logic as eval_to_string_eap(). (closes #7684)
Files:      src/vim9execute.c, src/eval.c, src/proto/eval.pro,
            src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2355/src/vim9execute.c   2021-01-14 21:47:03.171554574 +0100
--- src/vim9execute.c   2021-01-15 17:40:41.413564255 +0100
***************
*** 3357,3363 ****
                            expr = tv->vval.v_string;
                        else
                        {
!                           expr = typval_tostring(tv);  // allocates value
                            clear_tv(tv);
                        }
                        --ectx.ec_stack.ga_len;
--- 3357,3363 ----
                            expr = tv->vval.v_string;
                        else
                        {
!                           expr = typval2string(tv, TRUE); // allocates value
                            clear_tv(tv);
                        }
                        --ectx.ec_stack.ga_len;
*** ../vim-8.2.2355/src/eval.c  2021-01-13 21:46:53.832589880 +0100
--- src/eval.c  2021-01-15 17:41:19.725466268 +0100
***************
*** 467,472 ****
--- 467,511 ----
  }
  
  /*
+  * Convert "tv" to a string.
+  * When "convert" is TRUE convert a List into a sequence of lines and convert
+  * a Float to a String.
+  * Returns an allocated string (NULL when out of memory).
+  */
+     char_u *
+ typval2string(typval_T *tv, int convert)
+ {
+     garray_T  ga;
+     char_u    *retval;
+ #ifdef FEAT_FLOAT
+     char_u    numbuf[NUMBUFLEN];
+ #endif
+ 
+     if (convert && tv->v_type == VAR_LIST)
+     {
+       ga_init2(&ga, (int)sizeof(char), 80);
+       if (tv->vval.v_list != NULL)
+       {
+           list_join(&ga, tv->vval.v_list, (char_u *)"\n", TRUE, FALSE, 0);
+           if (tv->vval.v_list->lv_len > 0)
+               ga_append(&ga, NL);
+       }
+       ga_append(&ga, NUL);
+       retval = (char_u *)ga.ga_data;
+     }
+ #ifdef FEAT_FLOAT
+     else if (convert && tv->v_type == VAR_FLOAT)
+     {
+       vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv->vval.v_float);
+       retval = vim_strsave(numbuf);
+     }
+ #endif
+     else
+       retval = vim_strsave(tv_get_string(tv));
+     return retval;
+ }
+ 
+ /*
   * Top level evaluation function, returning a string.  Does not handle line
   * breaks.
   * When "convert" is TRUE convert a List into a sequence of lines and convert
***************
*** 481,490 ****
  {
      typval_T  tv;
      char_u    *retval;
-     garray_T  ga;
- #ifdef FEAT_FLOAT
-     char_u    numbuf[NUMBUFLEN];
- #endif
      evalarg_T evalarg;
  
      fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip);
--- 520,525 ----
***************
*** 492,518 ****
        retval = NULL;
      else
      {
!       if (convert && tv.v_type == VAR_LIST)
!       {
!           ga_init2(&ga, (int)sizeof(char), 80);
!           if (tv.vval.v_list != NULL)
!           {
!               list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, FALSE, 0);
!               if (tv.vval.v_list->lv_len > 0)
!                   ga_append(&ga, NL);
!           }
!           ga_append(&ga, NUL);
!           retval = (char_u *)ga.ga_data;
!       }
! #ifdef FEAT_FLOAT
!       else if (convert && tv.v_type == VAR_FLOAT)
!       {
!           vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", tv.vval.v_float);
!           retval = vim_strsave(numbuf);
!       }
! #endif
!       else
!           retval = vim_strsave(tv_get_string(&tv));
        clear_tv(&tv);
      }
      clear_evalarg(&evalarg, NULL);
--- 527,533 ----
        retval = NULL;
      else
      {
!       retval = typval2string(&tv, convert);
        clear_tv(&tv);
      }
      clear_evalarg(&evalarg, NULL);
*** ../vim-8.2.2355/src/proto/eval.pro  2021-01-13 21:46:53.832589880 +0100
--- src/proto/eval.pro  2021-01-15 17:40:47.321549114 +0100
***************
*** 11,16 ****
--- 11,17 ----
  char_u *eval_to_string_skip(char_u *arg, exarg_T *eap, int skip);
  int skip_expr(char_u **pp, evalarg_T *evalarg);
  int skip_expr_concatenate(char_u **arg, char_u **start, char_u **end, 
evalarg_T *evalarg);
+ char_u *typval2string(typval_T *tv, int convert);
  char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
  char_u *eval_to_string(char_u *arg, int convert);
  char_u *eval_to_string_safe(char_u *arg, int use_sandbox);
*** ../vim-8.2.2355/src/testdir/test_vim9_cmd.vim       2021-01-11 
22:16:26.547513748 +0100
--- src/testdir/test_vim9_cmd.vim       2021-01-15 17:51:53.451876176 +0100
***************
*** 736,741 ****
--- 736,744 ----
    assert_equal('above', getline(3))
    assert_equal('below', getline(4))
  
+   :2put =['a', 'b', 'c']
+   assert_equal(['ppp', 'a', 'b', 'c', 'above'], getline(2, 6))
+ 
    # compute range at runtime
    setline(1, range(1, 8))
    @a = 'aaa'
*** ../vim-8.2.2355/src/version.c       2021-01-15 16:45:18.144326653 +0100
--- src/version.c       2021-01-15 17:40:11.597640734 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2356,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
155. You forget to eat because you're too busy surfing the net.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202101151705.10FH5CLt020472%40masaka.moolenaar.net.

Raspunde prin e-mail lui