diff src/testdir/test_vim9_import.vim @ 27086:1e2a6c6c7e42 v8.2.4072

patch 8.2.4072: Vim9: compiling function fails when autoload is not loaded Commit: https://github.com/vim/vim/commit/d041f4208b0a2149e9d41f6443aa1c14c076a411 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 12 19:54:00 2022 +0000 patch 8.2.4072: Vim9: compiling function fails when autoload is not loaded Problem: Vim9: compiling function fails when autoload script is not loaded yet. Solution: Depend on runtime loading.
author Bram Moolenaar <Bram@vim.org>
date Wed, 12 Jan 2022 21:00:05 +0100
parents 9897dd3c6530
children d7e6b85dd89d
line wrap: on
line diff
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -1218,6 +1218,42 @@ def Test_vim9script_autoload_call()
   &rtp = save_rtp
 enddef
 
+def Test_import_autoload_postponed()
+  mkdir('Xdir/autoload', 'p')
+  var save_rtp = &rtp
+  exe 'set rtp^=' .. getcwd() .. '/Xdir'
+
+  var lines =<< trim END
+      vim9script autoload
+
+      g:loaded_postponed = 'true'
+      export var variable = 'bla'
+      export def Function(): string
+        return 'bla'
+      enddef
+  END
+  writefile(lines, 'Xdir/autoload/postponed.vim')
+
+  lines =<< trim END
+      vim9script
+
+      import autoload 'postponed.vim'
+      def Tryit()
+        echo postponed.variable
+        echo postponed.Function()
+      enddef
+      defcompile
+  END
+  CheckScriptSuccess(lines)
+  assert_false(exists('g:loaded_postponed'))
+  CheckScriptSuccess(lines + ['Tryit()'])
+  assert_equal('true', g:loaded_postponed)
+
+  unlet g:loaded_postponed
+  delete('Xdir', 'rf')
+  &rtp = save_rtp
+enddef
+
 def Test_autoload_mapping()
   mkdir('Xdir/autoload', 'p')
   var save_rtp = &rtp