]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0165: Vim9: Importing an autoload imported script fails v9.1.0165
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 10 Mar 2024 18:22:38 +0000 (19:22 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 10 Mar 2024 18:22:38 +0000 (19:22 +0100)
Problem:  Vim9: Importing an autoload imported script fails
          (Song-Tianxiang)
Solution: Return the script ID in this case
          (Yegappan Lakshmanan)

fixes: #14171
closes: #14174

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/scriptfile.c
src/testdir/test_vim9_import.vim
src/version.c

index 69016bfb1291ab1e7555239e2080b0d2e84adf19..6dc55579a8c2463c743a938a9c7c9d401c49fe40 100644 (file)
@@ -1690,6 +1690,8 @@ do_source_ext(
            // reset version, "vim9script" may have been added or removed.
            si->sn_version = 1;
        }
+       if (ret_sid != NULL)
+           *ret_sid = sid;
     }
     else
     {
index d470a346750dadd924a105762cee7c539755a47a..fa1aeb10e8f8619c4a2b074f0c241ce557097a6f 100644 (file)
@@ -2929,5 +2929,54 @@ def Test_export_in_conditional_block()
   v9.CheckScriptSuccess(lines)
 enddef
 
+" Import fails when an autoloaded script is imported again.
+" Github issue #14171
+def Test_import_autloaded_script()
+  mkdir('Ximporttwice', 'pR')
+  mkdir('Ximporttwice/plugin')
+  mkdir('Ximporttwice/autoload')
+  var save_rtp = &rtp
+  exe 'set rtp^=' .. getcwd() .. '/Ximporttwice'
+
+  var lines =<< trim END
+    vim9script
+
+    export def H(): number
+      return 10
+    enddef
+  END
+  writefile(lines, 'Ximporttwice/autoload/hello.vim')
+
+  lines =<< trim END
+    vim9script
+
+    import "./hello.vim"
+    export def W(): number
+      return 20
+    enddef
+  END
+  writefile(lines, 'Ximporttwice/autoload/world.vim')
+
+  lines =<< trim END
+    vim9script
+
+    import autoload '../autoload/hello.vim'
+    import autoload '../autoload/world.vim'
+
+    command Hello echo hello.H()
+    command World echo world.W()
+  END
+  writefile(lines, 'Ximporttwice/plugin/main.vim')
+
+  lines =<< trim END
+    vim9script
+
+    source ./Ximporttwice/plugin/main.vim
+    assert_equal(['20'], execute('World')->split("\n"))
+  END
+  v9.CheckScriptSuccess(lines)
+
+  &rtp = save_rtp
+enddef
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index b46b3558607ae311bab35af6e621d30bf6c7d2a8..e1b13bdd4e71e85bdd8fe60da0d1f4192f656d6f 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    165,
 /**/
     164,
 /**/