changeset 34522:a089397c9bc6 v9.1.0165

patch 9.1.0165: Vim9: Importing an autoload imported script fails Commit: https://github.com/vim/vim/commit/fa6300872732f80b770a768e785ae2b189d3e684 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Mar 10 19:22:38 2024 +0100 patch 9.1.0165: Vim9: Importing an autoload imported script fails 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>
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Mar 2024 19:30:03 +0100
parents 95a648080001
children 28465f94adbf
files src/scriptfile.c src/testdir/test_vim9_import.vim src/version.c
diffstat 3 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -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
     {
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -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
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    165,
+/**/
     164,
 /**/
     163,