Patch 8.2.4656
Problem:    Vim9: can't use items from "import autoload" with autoload
            directory name.
Solution:   Let sn_autoload_prefix overrule sn_import_autoload.
            (closes #10054)
Files:      src/structs.h, src/vim9instr.c, src/vim9expr.c, src/vim9script.c,
            src/testdir/test_vim9_import.vim


*** ../vim-8.2.4655/src/structs.h       2022-03-30 21:12:16.447923057 +0100
--- src/structs.h       2022-03-31 15:27:03.989702184 +0100
***************
*** 1868,1873 ****
--- 1868,1874 ----
      char_u    *sn_autoload_prefix;
  
      // TRUE for a script used with "import autoload './dirname/script.vim'"
+     // For "../autoload/script.vim" sn_autoload_prefix is also set.
      int               sn_import_autoload;
  
  # ifdef FEAT_PROFILE
*** ../vim-8.2.4655/src/vim9instr.c     2022-03-30 21:12:16.451923056 +0100
--- src/vim9instr.c     2022-03-31 15:30:31.893378056 +0100
***************
*** 1932,1938 ****
                isntype_T isn_type = ISN_STORES;
  
                if (SCRIPT_ID_VALID(scriptvar_sid)
!                        && SCRIPT_ITEM(scriptvar_sid)->sn_import_autoload)
                {
                    // "import autoload './dir/script.vim'" - load script first
                    if (generate_SOURCE(cctx, scriptvar_sid) == FAIL)
--- 1932,1940 ----
                isntype_T isn_type = ISN_STORES;
  
                if (SCRIPT_ID_VALID(scriptvar_sid)
!                        && SCRIPT_ITEM(scriptvar_sid)->sn_import_autoload
!                        && SCRIPT_ITEM(scriptvar_sid)->sn_autoload_prefix
!                                                                      == NULL)
                {
                    // "import autoload './dir/script.vim'" - load script first
                    if (generate_SOURCE(cctx, scriptvar_sid) == FAIL)
*** ../vim-8.2.4655/src/vim9expr.c      2022-03-30 21:12:16.451923056 +0100
--- src/vim9expr.c      2022-03-31 16:11:01.971933148 +0100
***************
*** 298,323 ****
        *p = NUL;
  
        si = SCRIPT_ITEM(import->imp_sid);
!       if (si->sn_autoload_prefix != NULL
!                                       && si->sn_state == SN_STATE_NOT_LOADED)
!       {
!           char_u  *auto_name = concat_str(si->sn_autoload_prefix, exp_name);
  
!           // autoload script must be loaded later, access by the autoload
!           // name.  If a '(' follows it must be a function.  Otherwise we
!           // don't know, it can be "script.Func".
!           if (cc == '(' || paren_follows_after_expr)
!               res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
!           else
!               res = generate_AUTOLOAD(cctx, auto_name, &t_any);
!           vim_free(auto_name);
!           done = TRUE;
!       }
!       else if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
        {
!           // "import autoload './dir/script.vim'" - load script first
!           res = generate_SOURCE(cctx, import->imp_sid);
!           if (res == OK)
            {
                // If a '(' follows it must be a function.  Otherwise we don't
                // know, it can be "script.Func".
--- 298,328 ----
        *p = NUL;
  
        si = SCRIPT_ITEM(import->imp_sid);
!       if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
!           // "import autoload './dir/script.vim'" or
!           // "import autoload './autoload/script.vim'" - load script first
!           res = generate_SOURCE(cctx, import->imp_sid);
  
!       if (res == OK)
        {
!           if (si->sn_autoload_prefix != NULL
!                                       && si->sn_state == SN_STATE_NOT_LOADED)
!           {
!               char_u  *auto_name =
!                                 concat_str(si->sn_autoload_prefix, exp_name);
! 
!               // autoload script must be loaded later, access by the autoload
!               // name.  If a '(' follows it must be a function.  Otherwise we
!               // don't know, it can be "script.Func".
!               if (cc == '(' || paren_follows_after_expr)
!                   res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
!               else
!                   res = generate_AUTOLOAD(cctx, auto_name, &t_any);
!               vim_free(auto_name);
!               done = TRUE;
!           }
!           else if (si->sn_import_autoload
!                                       && si->sn_state == SN_STATE_NOT_LOADED)
            {
                // If a '(' follows it must be a function.  Otherwise we don't
                // know, it can be "script.Func".
***************
*** 331,344 ****
                else
                    res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
                                                      import->imp_sid, &t_any);
            }
-           done = TRUE;
-       }
-       else
-       {
-           idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
-                                                           cctx, NULL, TRUE);
        }
        *p = cc;
        *end = p;
        if (done)
--- 336,350 ----
                else
                    res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
                                                      import->imp_sid, &t_any);
+               done = TRUE;
+           }
+           else
+           {
+               idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
+                                                            cctx, NULL, TRUE);
            }
        }
+ 
        *p = cc;
        *end = p;
        if (done)
*** ../vim-8.2.4655/src/vim9script.c    2022-03-31 11:51:18.047324194 +0100
--- src/vim9script.c    2022-03-31 15:44:04.073397137 +0100
***************
*** 415,420 ****
--- 415,423 ----
        si = SCRIPT_ITEM(*sid);
        si->sn_import_autoload = TRUE;
  
+       if (si->sn_autoload_prefix == NULL)
+           si->sn_autoload_prefix = get_autoload_prefix(si);
+ 
        // with testing override: load autoload script right away
        if (!override_autoload || si->sn_state != SN_STATE_NOT_LOADED)
            return OK;
*** ../vim-8.2.4655/src/testdir/test_vim9_import.vim    2022-03-31 
11:37:54.263367943 +0100
--- src/testdir/test_vim9_import.vim    2022-03-31 16:02:38.860489574 +0100
***************
*** 969,974 ****
--- 969,999 ----
    delete('XimportRel3.vim')
  enddef
  
+ def Test_autoload_import_relative_autoload_dir()
+   mkdir('autoload', 'p')
+   var lines =<< trim END
+       vim9script
+       export def Bar()
+         g:called_bar = 'yes'
+       enddef
+   END
+   writefile(lines, 'autoload/script.vim')
+ 
+   lines =<< trim END
+       vim9script
+       import autoload './autoload/script.vim'
+       def Foo()
+         script.Bar()
+       enddef
+       Foo()
+       assert_equal('yes', g:called_bar)
+   END
+   v9.CheckScriptSuccess(lines)
+ 
+   unlet g:called_bar
+   delete('autoload', 'rf')
+ enddef
+ 
  func Test_import_in_diffexpr()
    CheckExecutable diff
  
*** ../vim-8.2.4655/src/version.c       2022-03-31 12:33:56.485701120 +0100
--- src/version.c       2022-03-31 15:58:41.916788975 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4656,
  /**/

-- 
Save the plankton - eat a whale.

 /// 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/20220331151855.C0CB71C13F2%40moolenaar.net.

Raspunde prin e-mail lui