]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1503: Vim9: error for autocmd defined in :def in legacy script v8.2.1503
authorBram Moolenaar <Bram@vim.org>
Fri, 21 Aug 2020 19:55:43 +0000 (21:55 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 21 Aug 2020 19:55:43 +0000 (21:55 +0200)
Problem:    Vim9: error for an autocmd defined in a :def function in legacy
            Vim script.
Solution:   Don't check the variable type. (closes #6758)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9script.c

index 91867f2202d39d5e48d2e3404baf9fd2f9da5066..5a251473cdd0fa4ed10fdd9c87775ca1db346920 100644 (file)
@@ -3166,6 +3166,23 @@ def Test_vim9_autoload()
   &rtp = save_rtp
 enddef
 
+def Test_script_var_in_autocmd()
+  # using a script variable from an autocommand, defined in a :def function in a
+  # legacy Vim script, cannot check the variable type.
+  let lines =<< trim END
+    let s:counter = 1
+    def s:Func()
+      au! CursorHold
+      au CursorHold * s:counter += 1
+    enddef
+    call s:Func()
+    doau CursorHold
+    call assert_equal(2, s:counter)
+    au! CursorHold
+  END
+  CheckScriptSuccess(lines)
+enddef
+
 def Test_cmdline_win()
   # if the Vim syntax highlighting uses Vim9 constructs they can be used from
   # the command line window.
index 62692b82fbde6790b837220741f0fc477bf8f048..fe2a7ad18ed4ea54a7fcb3293b499a8483428c85 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1503,
 /**/
     1502,
 /**/
index e04c0f0c2e336a5bf3d4edc32e8084f6ad64f357..b9dc5d7f2eca904157924ee70302f08103c0317c 100644 (file)
@@ -564,6 +564,10 @@ check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
     scriptitem_T    *si = SCRIPT_ITEM(current_sctx.sc_sid);
     int                    idx;
 
+    if (si->sn_version != SCRIPT_VERSION_VIM9)
+       // legacy script doesn't store variable types
+       return OK;
+
     // Find the svar_T in sn_var_vals.
     for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx)
     {