Patch 8.2.2729
Problem:    Vim9: wrong error message for referring to legacy script variable.
Solution:   Do allow referring to a variable in legacy script without "s:" if
            it exists at compile time. (closes #8076)
Files:      src/vim9compile.c, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.2728/src/vim9compile.c   2021-04-05 20:50:56.548776807 +0200
--- src/vim9compile.c   2021-04-06 21:09:27.619484246 +0200
***************
*** 5708,5724 ****
            return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
        case dest_script:
            if (scriptvar_idx < 0)
!           {
!               char_u  *name_s = name;
!               int     r;
! 
!               // "s:" is included in the name.
!               r = generate_OLDSCRIPT(cctx, ISN_STORES, name_s,
                                                          scriptvar_sid, type);
-               if (name_s != name)
-                   vim_free(name_s);
-               return r;
-           }
            return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
                                           scriptvar_sid, scriptvar_idx, type);
        case dest_local:
--- 5708,5716 ----
            return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
        case dest_script:
            if (scriptvar_idx < 0)
!               // "s:" may be included in the name.
!               return generate_OLDSCRIPT(cctx, ISN_STORES, name,
                                                          scriptvar_sid, type);
            return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
                                           scriptvar_sid, scriptvar_idx, type);
        case dest_local:
***************
*** 5854,5860 ****
                        ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
                                                               FALSE, cctx)
                          : script_var_exists(var_start, lhs->lhs_varlen,
!                                                           TRUE, cctx)) == OK;
                imported_T  *import =
                               find_imported(var_start, lhs->lhs_varlen, cctx);
  
--- 5846,5852 ----
                        ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
                                                               FALSE, cctx)
                          : script_var_exists(var_start, lhs->lhs_varlen,
!                                                          FALSE, cctx)) == OK;
                imported_T  *import =
                               find_imported(var_start, lhs->lhs_varlen, cctx);
  
*** ../vim-8.2.2728/src/testdir/test_vim9_assign.vim    2021-04-05 
21:05:23.102398492 +0200
--- src/testdir/test_vim9_assign.vim    2021-04-06 21:16:29.310289803 +0200
***************
*** 1476,1481 ****
--- 1476,1516 ----
    CheckDefFailure(['const foo: number'], 'E1021:')
  enddef
  
+ def Test_script_local_in_legacy()
+   # OK to define script-local later when prefixed with s:
+   var lines =<< trim END
+     def SetLater()
+       s:legacy = 'two'
+     enddef
+     defcompile
+     let s:legacy = 'one'
+     call SetLater()
+     call assert_equal('two', s:legacy)
+   END
+   CheckScriptSuccess(lines)
+ 
+   # OK to leave out s: prefix when script-local already defined
+   lines =<< trim END
+     let s:legacy = 'one'
+     def SetNoPrefix()
+       legacy = 'two'
+     enddef
+     call SetNoPrefix()
+     call assert_equal('two', s:legacy)
+   END
+   CheckScriptSuccess(lines)
+ 
+   # Not OK to leave out s: prefix when script-local defined later
+   lines =<< trim END
+     def SetLaterNoPrefix()
+       legacy = 'two'
+     enddef
+     defcompile
+     let s:legacy = 'one'
+   END
+   CheckScriptFailure(lines, 'E476:', 1)
+ enddef
+ 
  def Test_var_type_check()
    var lines =<< trim END
      vim9script
*** ../vim-8.2.2728/src/version.c       2021-04-06 20:21:55.299147728 +0200
--- src/version.c       2021-04-06 21:08:08.323719743 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2729,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
75. You start wondering whether you could actually upgrade your brain
    with a Pentium Pro microprocessor 80.  The upgrade works just fine.

 /// 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/202104061918.136JI40l3417895%40masaka.moolenaar.net.

Raspunde prin e-mail lui