Patch 8.2.3347
Problem:    Check for legacy script is incomplete. (Naohiro Ono)
Solution:   Also check the :legacy modifier.  Use for string concatenation
            with "." and others (issue #8756)
Files:      src/vim9script.c, src/proto/vim9script.pro, src/eval.c,
            src/typval.c, src/evalvars.c, src/errors.h, src/ex_docmd.c,
            src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.3346/src/vim9script.c    2021-08-09 19:59:01.446811234 +0200
--- src/vim9script.c    2021-08-15 13:09:14.163664622 +0200
***************
*** 34,39 ****
--- 34,51 ----
  
  #if defined(FEAT_EVAL) || defined(PROTO)
  /*
+  * Return TRUE when currently in a script with script version smaller than
+  * "max_version" or command modifiers forced it.
+  */
+     int
+ in_old_script(int max_version)
+ {
+     return (current_sctx.sc_version <= max_version
+                                        && !(cmdmod.cmod_flags & CMOD_VIM9CMD))
+               || (cmdmod.cmod_flags & CMOD_LEGACY);
+ }
+ 
+ /*
   * Return TRUE if the current script is Vim9 script.
   * This also returns TRUE in a legacy function in a Vim9 script.
   */
*** ../vim-8.2.3346/src/proto/vim9script.pro    2021-08-09 19:59:01.442811242 
+0200
--- src/proto/vim9script.pro    2021-08-15 13:13:14.783199499 +0200
***************
*** 1,5 ****
--- 1,6 ----
  /* vim9script.c */
  int in_vim9script(void);
+ int in_old_script(int max_version);
  int current_script_is_vim9(void);
  void ex_vim9script(exarg_T *eap);
  int not_in_vim9(exarg_T *eap);
*** ../vim-8.2.3346/src/eval.c  2021-08-14 21:35:37.674334163 +0200
--- src/eval.c  2021-08-15 13:13:00.059228100 +0200
***************
*** 2860,2867 ****
        // "++" and "--" on the next line are a separate command.
        p = eval_next_non_blank(*arg, evalarg, &getnext);
        op = *p;
!       concat = op == '.' && (*(p + 1) == '.'
!                             || (current_sctx.sc_version < 2 && !vim9script));
        if ((op != '+' && op != '-' && !concat) || p[1] == '='
                                               || (p[1] == '.' && p[2] == '='))
            break;
--- 2860,2866 ----
        // "++" and "--" on the next line are a separate command.
        p = eval_next_non_blank(*arg, evalarg, &getnext);
        op = *p;
!       concat = op == '.' && (*(p + 1) == '.' || in_old_script(2));
        if ((op != '+' && op != '-' && !concat) || p[1] == '='
                                               || (p[1] == '.' && p[2] == '='))
            break;
***************
*** 3402,3408 ****
  
      if (**arg == '.' && (!isdigit(*(*arg + 1))
  #ifdef FEAT_FLOAT
!           || current_sctx.sc_version < 2
  #endif
            ))
      {
--- 3401,3407 ----
  
      if (**arg == '.' && (!isdigit(*(*arg + 1))
  #ifdef FEAT_FLOAT
!           || in_old_script(2)
  #endif
            ))
      {
***************
*** 5877,5883 ****
                || (**arg == '.' && (rettv->v_type == VAR_DICT
                        || (!evaluate
                            && (*arg)[1] != '.'
!                           && current_sctx.sc_version >= 2))))
        {
            dict_unref(selfdict);
            if (rettv->v_type == VAR_DICT)
--- 5876,5882 ----
                || (**arg == '.' && (rettv->v_type == VAR_DICT
                        || (!evaluate
                            && (*arg)[1] != '.'
!                           && !in_old_script(2)))))
        {
            dict_unref(selfdict);
            if (rettv->v_type == VAR_DICT)
*** ../vim-8.2.3346/src/typval.c        2021-08-11 16:47:20.947942681 +0200
--- src/typval.c        2021-08-15 13:18:52.142542008 +0200
***************
*** 1704,1710 ****
        int         want_string UNUSED)
  {
      int               len;
!     int               skip_quotes = current_sctx.sc_version >= 4 || 
in_vim9script();
  #ifdef FEAT_FLOAT
      char_u    *p;
      int               get_float = FALSE;
--- 1704,1710 ----
        int         want_string UNUSED)
  {
      int               len;
!     int               skip_quotes = !in_old_script(4);
  #ifdef FEAT_FLOAT
      char_u    *p;
      int               get_float = FALSE;
*** ../vim-8.2.3346/src/evalvars.c      2021-08-14 14:59:21.919933809 +0200
--- src/evalvars.c      2021-08-15 13:27:37.969508217 +0200
***************
*** 774,780 ****
        --argend;
      expr = skipwhite(argend);
      concat = expr[0] == '.'
!       && ((expr[1] == '=' && current_sctx.sc_version < 2)
                || (expr[1] == '.' && expr[2] == '='));
      has_assign =  *expr == '=' || (vim_strchr((char_u *)"+-*/%", *expr) != 
NULL
                                                            && expr[1] == '=');
--- 774,780 ----
        --argend;
      expr = skipwhite(argend);
      concat = expr[0] == '.'
!       && ((expr[1] == '=' && in_old_script(2))
                || (expr[1] == '.' && expr[2] == '='));
      has_assign =  *expr == '=' || (vim_strchr((char_u *)"+-*/%", *expr) != 
NULL
                                                            && expr[1] == '=');
***************
*** 2932,2938 ****
  
        // "version" is "v:version" in all scopes if scriptversion < 3.
        // Same for a few other variables marked with VV_COMPAT.
!       if (current_sctx.sc_version < 3)
        {
            hi = hash_find(&compat_hashtab, name);
            if (!HASHITEM_EMPTY(hi))
--- 2932,2938 ----
  
        // "version" is "v:version" in all scopes if scriptversion < 3.
        // Same for a few other variables marked with VV_COMPAT.
!       if (in_old_script(3))
        {
            hi = hash_find(&compat_hashtab, name);
            if (!HASHITEM_EMPTY(hi))
*** ../vim-8.2.3346/src/errors.h        2021-08-08 14:41:48.723930691 +0200
--- src/errors.h        2021-08-15 13:35:21.396593961 +0200
***************
*** 650,652 ****
--- 650,654 ----
        INIT(= N_("E1232: Argument of exists_compiled() must be a literal 
string"));
  EXTERN char e_exists_compiled_can_only_be_used_in_def_function[]
        INIT(= N_("E1233: exists_compiled() can only be used in a :def 
function"));
+ EXTERN char e_legacy_must_be_followed_by_command[]
+       INIT(= N_("E1234: legacy must be followed by a command"));
*** ../vim-8.2.3346/src/ex_docmd.c      2021-08-10 19:52:57.474235537 +0200
--- src/ex_docmd.c      2021-08-15 13:41:25.031876159 +0200
***************
*** 2951,2957 ****
                            if (ends_excmd2(p, eap->cmd))
                            {
                                *errormsg =
!                                     _(e_vim9cmd_must_be_followed_by_command);
                                return FAIL;
                            }
                            cmod->cmod_flags |= CMOD_LEGACY;
--- 2951,2957 ----
                            if (ends_excmd2(p, eap->cmd))
                            {
                                *errormsg =
!                                     _(e_legacy_must_be_followed_by_command);
                                return FAIL;
                            }
                            cmod->cmod_flags |= CMOD_LEGACY;
*** ../vim-8.2.3346/src/testdir/test_vim9_cmd.vim       2021-08-14 
21:35:37.674334163 +0200
--- src/testdir/test_vim9_cmd.vim       2021-08-15 13:40:46.327952656 +0200
***************
*** 13,22 ****
--- 13,38 ----
      vim9cm assert_equal('yes', y)
    END
    CheckScriptSuccess(lines)
+ 
    assert_fails('vim9cmd', 'E1164:')
+   assert_fails('legacy', 'E1234:')
    assert_fails('vim9cmd echo "con" . "cat"', 'E15:')
  
    lines =<< trim END
+       let str = 'con'
+       vim9cmd str .= 'cat'
+   END
+   CheckScriptFailure(lines, 'E492:')
+ 
+   lines =<< trim END
+       vim9script
+       legacy echo "con" . "cat"
+       legacy let str = 'con'
+       legacy let str .= 'cat'
+   END
+   CheckScriptSuccess(lines)
+ 
+   lines =<< trim END
        vim9script
        def Foo()
          g:found_bar = "bar"
***************
*** 24,34 ****
        nmap ,; :vim9cmd <SID>Foo()<CR>
    END
    CheckScriptSuccess(lines)
    feedkeys(',;', 'xt')
    assert_equal("bar", g:found_bar)
- 
    nunmap ,;
    unlet g:found_bar
  enddef
  
  def Test_edit_wildcards()
--- 40,86 ----
        nmap ,; :vim9cmd <SID>Foo()<CR>
    END
    CheckScriptSuccess(lines)
+ 
    feedkeys(',;', 'xt')
    assert_equal("bar", g:found_bar)
    nunmap ,;
    unlet g:found_bar
+ 
+   lines =<< trim END
+       vim9script
+       legacy echo 1'000
+   END
+   CheckScriptFailure(lines, 'E115:')
+ 
+   if has('float')
+     lines =<< trim END
+         vim9script
+         echo .10
+     END
+     CheckScriptSuccess(lines)
+     lines =<< trim END
+         vim9cmd echo .10
+     END
+     CheckScriptSuccess(lines)
+     lines =<< trim END
+         vim9script
+         legacy echo .10
+     END
+     CheckScriptFailure(lines, 'E15:')
+   endif
+ 
+   echo v:version
+   assert_fails('vim9cmd echo version', 'E121:')
+   lines =<< trim END
+       vim9script
+       echo version
+   END
+   CheckScriptFailure(lines, 'E121:')
+   lines =<< trim END
+       vim9script
+       legacy echo version
+   END
+   CheckScriptSuccess(lines)
  enddef
  
  def Test_edit_wildcards()
*** ../vim-8.2.3346/src/version.c       2021-08-14 21:35:37.674334163 +0200
--- src/version.c       2021-08-15 13:49:04.158972442 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3347,
  /**/

-- 
Compilation process failed successfully.

 /// 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/202108151150.17FBoGmR3982951%40masaka.moolenaar.net.

Raspunde prin e-mail lui