Patch 8.2.4934
Problem:    String interpolation fails when not evaluating.
Solution:   Skip the expression when not evaluating. (closes #10398)
Files:      src/typval.c, src/evalvars.c, src/proto/evalvars.pro,
            src/testdir/test_vim9_expr.vim


*** ../vim-8.2.4933/src/typval.c        2022-05-10 13:24:17.628706903 +0100
--- src/typval.c        2022-05-10 18:11:14.959461523 +0100
***************
*** 2363,2369 ****
            ++*arg;
            break;
        }
!       p = eval_one_expr_in_str(*arg, &ga);
        if (p == NULL)
        {
            ret = FAIL;
--- 2363,2369 ----
            ++*arg;
            break;
        }
!       p = eval_one_expr_in_str(*arg, &ga, evaluate);
        if (p == NULL)
        {
            ret = FAIL;
*** ../vim-8.2.4933/src/evalvars.c      2022-05-10 13:24:17.632706901 +0100
--- src/evalvars.c      2022-05-10 18:07:20.391529312 +0100
***************
*** 605,614 ****
  /*
   * Evaluate one Vim expression {expr} in string "p" and append the
   * resulting string to "gap".  "p" points to the opening "{".
   * Return a pointer to the character after "}", NULL for an error.
   */
      char_u *
! eval_one_expr_in_str(char_u *p, garray_T *gap)
  {
      char_u    *block_start = skipwhite(p + 1);  // skip the opening {
      char_u    *block_end = block_start;
--- 605,615 ----
  /*
   * Evaluate one Vim expression {expr} in string "p" and append the
   * resulting string to "gap".  "p" points to the opening "{".
+  * When "evaluate" is FALSE only skip over the expression.
   * Return a pointer to the character after "}", NULL for an error.
   */
      char_u *
! eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate)
  {
      char_u    *block_start = skipwhite(p + 1);  // skip the opening {
      char_u    *block_end = block_start;
***************
*** 627,639 ****
        semsg(_(e_missing_close_curly_str), p);
        return NULL;
      }
!     *block_end = NUL;
!     expr_val = eval_to_string(block_start, TRUE);
!     *block_end = '}';
!     if (expr_val == NULL)
!       return NULL;
!     ga_concat(gap, expr_val);
!     vim_free(expr_val);
  
      return block_end + 1;
  }
--- 628,643 ----
        semsg(_(e_missing_close_curly_str), p);
        return NULL;
      }
!     if (evaluate)
!     {
!       *block_end = NUL;
!       expr_val = eval_to_string(block_start, TRUE);
!       *block_end = '}';
!       if (expr_val == NULL)
!           return NULL;
!       ga_concat(gap, expr_val);
!       vim_free(expr_val);
!     }
  
      return block_end + 1;
  }
***************
*** 691,697 ****
        }
  
        // Evaluate the expression and append the result.
!       p = eval_one_expr_in_str(p, &ga);
        if (p == NULL)
        {
            ga_clear(&ga);
--- 695,701 ----
        }
  
        // Evaluate the expression and append the result.
!       p = eval_one_expr_in_str(p, &ga, TRUE);
        if (p == NULL)
        {
            ga_clear(&ga);
*** ../vim-8.2.4933/src/proto/evalvars.pro      2022-05-10 13:24:17.632706901 
+0100
--- src/proto/evalvars.pro      2022-05-10 18:07:31.355526189 +0100
***************
*** 13,19 ****
  int get_spellword(list_T *list, char_u **pp);
  void prepare_vimvar(int idx, typval_T *save_tv);
  void restore_vimvar(int idx, typval_T *save_tv);
! char_u *eval_one_expr_in_str(char_u *p, garray_T *gap);
  char_u *eval_all_expr_in_str(char_u *str);
  list_T *heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int 
vim9compile);
  void ex_var(exarg_T *eap);
--- 13,19 ----
  int get_spellword(list_T *list, char_u **pp);
  void prepare_vimvar(int idx, typval_T *save_tv);
  void restore_vimvar(int idx, typval_T *save_tv);
! char_u *eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate);
  char_u *eval_all_expr_in_str(char_u *str);
  list_T *heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int 
vim9compile);
  void ex_var(exarg_T *eap);
*** ../vim-8.2.4933/src/testdir/test_vim9_expr.vim      2022-05-08 
16:36:55.212009370 +0100
--- src/testdir/test_vim9_expr.vim      2022-05-10 18:10:17.223478390 +0100
***************
*** 2156,2161 ****
--- 2156,2168 ----
                ->split($'x{x}x')
                ->map((_, v: string) => v =~ 'bar')
    assert_equal([false, true, false], vl)
+ 
+   # interpolated string in a lambda
+   lines =<< trim END
+       assert_equal(['gnome-256color', 'xterm-256color'], ['gnome', 'xterm']
+               ->map((_, term: string) => $'{term}-256color'))
+   END
+   v9.CheckDefAndScriptSuccess(lines)
  enddef
  
  def Test_expr8_vimvar()
*** ../vim-8.2.4933/src/version.c       2022-05-10 17:51:51.391754834 +0100
--- src/version.c       2022-05-10 18:10:46.055469975 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4934,
  /**/

-- 
"The question of whether computers can think is just like the question
of whether submarines can swim."      -- Edsger W. Dijkstra

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20220510171211.548B71C0645%40moolenaar.net.

Raspunde prin e-mail lui