Patch 8.2.4940
Problem:    Some code is never used.
Solution:   Remove dead code.  Add a few more test cases.
Files:      src/vim9expr.c, src/proto/vim9expr.pro, src/vim9compile.c,
            src/testdir/test_vim9_builtin.vim, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.4939/src/vim9expr.c      2022-05-10 13:24:17.636706899 +0100
--- src/vim9expr.c      2022-05-11 20:31:20.354665653 +0100
***************
*** 140,148 ****
            typep->type_curr = &t_any;
            typep->type_decl = &t_any;
        }
!       if (may_generate_2STRING(-1, FALSE, cctx) == FAIL)
!           return FAIL;
!       if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL)
            return FAIL;
        if (keeping_dict != NULL)
            *keeping_dict = TRUE;
--- 140,147 ----
            typep->type_curr = &t_any;
            typep->type_decl = &t_any;
        }
!       if (may_generate_2STRING(-1, FALSE, cctx) == FAIL
!               || generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL)
            return FAIL;
        if (keeping_dict != NULL)
            *keeping_dict = TRUE;
***************
*** 246,253 ****
        cctx_T *cctx,
        char_u *name,       // variable NUL terminated
        char_u *start,      // start of variable
!       char_u **end,       // end of variable, may be NULL
!       int    error)       // when TRUE may give error
  {
      scriptitem_T    *si;
      int                   idx;
--- 245,251 ----
        cctx_T *cctx,
        char_u *name,       // variable NUL terminated
        char_u *start,      // start of variable
!       char_u **end)       // end of variable, may be NULL
  {
      scriptitem_T    *si;
      int                   idx;
***************
*** 368,381 ****
        return OK;
      }
  
!     if (idx == -1 || si->sn_version != SCRIPT_VERSION_VIM9)
!       // variable is not in sn_var_vals: old style script.
!       return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid,
                                                                       &t_any);
- 
-     if (error)
-       semsg(_(e_item_not_found_str), name);
-     return FAIL;
  }
  
      static int
--- 366,375 ----
        return OK;
      }
  
!     // Can only get here if we know "name" is a script variable and not in a
!     // Vim9 script (variable is not in sn_var_vals): old style script.
!     return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid,
                                                                       &t_any);
  }
  
      static int
***************
*** 462,468 ****
                              res = generate_funcref(cctx, name, FALSE);
                          else
                              res = compile_load_scriptvar(cctx, name,
!                                                           NULL, &end, error);
                          break;
                case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
                          {
--- 456,462 ----
                              res = generate_funcref(cctx, name, FALSE);
                          else
                              res = compile_load_scriptvar(cctx, name,
!                                                                  NULL, &end);
                          break;
                case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
                          {
***************
*** 538,544 ****
                // already exists in a Vim9 script or when it's imported.
                if (script_var_exists(*arg, len, cctx, NULL) == OK
                                      || find_imported(name, 0, FALSE) != NULL)
!                  res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
  
                // When evaluating an expression and the name starts with an
                // uppercase letter it can be a user defined function.
--- 532,538 ----
                // already exists in a Vim9 script or when it's imported.
                if (script_var_exists(*arg, len, cctx, NULL) == OK
                                      || find_imported(name, 0, FALSE) != NULL)
!                  res = compile_load_scriptvar(cctx, name, *arg, &end);
  
                // When evaluating an expression and the name starts with an
                // uppercase letter it can be a user defined function.
*** ../vim-8.2.4939/src/proto/vim9expr.pro      2021-12-20 15:03:23.247346527 
+0000
--- src/proto/vim9expr.pro      2022-05-11 20:30:41.082726064 +0100
***************
*** 2,8 ****
  int generate_ppconst(cctx_T *cctx, ppconst_T *ppconst);
  void clear_ppconst(ppconst_T *ppconst);
  int compile_member(int is_slice, int *keeping_dict, cctx_T *cctx);
! int compile_load_scriptvar(cctx_T *cctx, char_u *name, char_u *start, char_u 
**end, int error);
  int compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int is_expr, 
int error);
  char_u *to_name_end(char_u *arg, int use_namespace);
  char_u *to_name_const_end(char_u *arg);
--- 2,8 ----
  int generate_ppconst(cctx_T *cctx, ppconst_T *ppconst);
  void clear_ppconst(ppconst_T *ppconst);
  int compile_member(int is_slice, int *keeping_dict, cctx_T *cctx);
! int compile_load_scriptvar(cctx_T *cctx, char_u *name, char_u *start, char_u 
**end);
  int compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int is_expr, 
int error);
  char_u *to_name_end(char_u *arg, int use_namespace);
  char_u *to_name_const_end(char_u *arg);
*** ../vim-8.2.4939/src/vim9compile.c   2022-05-10 13:24:17.632706901 +0100
--- src/vim9compile.c   2022-05-11 20:30:54.042706089 +0100
***************
*** 1140,1146 ****
            break;
        case dest_script:
            compile_load_scriptvar(cctx,
!                   name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE);
            break;
        case dest_env:
            // Include $ in the name here
--- 1140,1146 ----
            break;
        case dest_script:
            compile_load_scriptvar(cctx,
!                                 name + (name[1] == ':' ? 2 : 0), NULL, NULL);
            break;
        case dest_env:
            // Include $ in the name here
*** ../vim-8.2.4939/src/testdir/test_vim9_builtin.vim   2022-05-10 
17:49:33.259775085 +0100
--- src/testdir/test_vim9_builtin.vim   2022-05-11 20:48:33.859001145 +0100
***************
*** 4083,4088 ****
--- 4083,4093 ----
      assert_equal("4", substitute("3", '\d', '\=str2nr(submatch(0)) + 1', 'g'))
    END
    v9.CheckDefAndScriptSuccess(lines)
+ 
+   lines =<< trim END
+     assert_equal("4", substitute("3", '\d', '\="text" x', 'g'))
+   END
+   v9.CheckDefAndScriptFailure(lines, 'E488: Trailing characters: x')
  enddef
  
  def Test_swapinfo()
*** ../vim-8.2.4939/src/testdir/test_vim9_expr.vim      2022-05-10 
18:11:39.627454291 +0100
--- src/testdir/test_vim9_expr.vim      2022-05-11 20:40:21.883014799 +0100
***************
*** 2695,2700 ****
--- 2695,2715 ----
        Test()
    END
    v9.CheckScriptSuccess(lines)
+ 
+   # using funcref in legacy script
+   lines =<< trim END
+       def s:Refme(): string
+         return 'yes'
+       enddef
+ 
+       def TestFunc()
+         var TheRef = s:Refme
+         assert_equal('yes', TheRef())
+       enddef
+ 
+       call TestFunc()
+   END
+   v9.CheckScriptSuccess(lines)
  enddef
  
  let g:test_space_dict = {'': 'empty', ' ': 'space'}
*** ../vim-8.2.4939/src/version.c       2022-05-11 14:15:32.343235976 +0100
--- src/version.c       2022-05-11 20:41:03.415031517 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4940,
  /**/

-- 
If Microsoft would build a car...
... Occasionally, executing a maneuver such as a left turn
would cause your car to shut down and refuse to restart, in
which case you would have to reinstall the engine.

 /// 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/20220512100840.297DB1C1209%40moolenaar.net.

Raspunde prin e-mail lui