Patch 8.2.4264
Problem:    Vim9: can use old style autoload function name.
Solution:   Give an error for old style autoload function name.
Files:      src/errors.h, src/userfunc.c, src/testdir/test_vim9_import.vim,
            src/testdir/test_vim9_func.vim, src/testdir/test_vim9_script.vim


*** ../vim-8.2.4263/src/errors.h        2022-01-28 21:00:47.659144775 +0000
--- src/errors.h        2022-01-30 18:23:36.394622009 +0000
***************
*** 3218,3225 ****
        INIT(= N_("E1261: Cannot import .vim without using \"as\""));
  EXTERN char e_cannot_import_same_script_twice_str[]
        INIT(= N_("E1262: Cannot import the same script twice: %s"));
! EXTERN char e_using_autoload_name_in_non_autoload_script_str[]
!       INIT(= N_("E1263: Using autoload name in a non-autoload script: %s"));
  EXTERN char e_autoload_import_cannot_use_absolute_or_relative_path[]
        INIT(= N_("E1264: Autoload import cannot use absolute or relative path: 
%s"));
  EXTERN char e_cannot_use_partial_here[]
--- 3218,3225 ----
        INIT(= N_("E1261: Cannot import .vim without using \"as\""));
  EXTERN char e_cannot_import_same_script_twice_str[]
        INIT(= N_("E1262: Cannot import the same script twice: %s"));
! EXTERN char e_cannot_use_name_with_hash_in_vim9_script_use_export_instead[]
!       INIT(= N_("E1263: cannot use name with # in Vim9 script, use export 
instead"));
  EXTERN char e_autoload_import_cannot_use_absolute_or_relative_path[]
        INIT(= N_("E1264: Autoload import cannot use absolute or relative path: 
%s"));
  EXTERN char e_cannot_use_partial_here[]
*** ../vim-8.2.4263/src/userfunc.c      2022-01-30 15:28:26.642295028 +0000
--- src/userfunc.c      2022-01-30 18:22:31.495602792 +0000
***************
*** 4232,4237 ****
--- 4232,4242 ----
                name = prefixed;
            }
        }
+       else if (vim9script && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
+       {
+           
emsg(_(e_cannot_use_name_with_hash_in_vim9_script_use_export_instead));
+           goto ret_free;
+       }
      }
  
      // An error in a function call during evaluation of an expression in magic
***************
*** 4540,4551 ****
                    }
                }
            }
-           else if (vim9script && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
-           {
-               semsg(_(e_using_autoload_name_in_non_autoload_script_str),
-                                                                        name);
-               goto erret;
-           }
        }
        if (var_conflict)
        {
--- 4545,4550 ----
*** ../vim-8.2.4263/src/testdir/test_vim9_import.vim    2022-01-30 
15:28:26.646294975 +0000
--- src/testdir/test_vim9_import.vim    2022-01-30 18:26:22.964110620 +0000
***************
*** 1614,1626 ****
  def Test_vim9_autoload_full_name()
    var lines =<< trim END
       vim9script
!      def some#gettest(): string
         return 'test'
       enddef
       g:some#name = 'name'
       g:some#dict = {key: 'value'}
  
!      def some#varargs(a1: string, ...l: list<string>): string
         return a1 .. l[0] .. l[1]
       enddef
    END
--- 1614,1626 ----
  def Test_vim9_autoload_full_name()
    var lines =<< trim END
       vim9script
!      export def Gettest(): string
         return 'test'
       enddef
       g:some#name = 'name'
       g:some#dict = {key: 'value'}
  
!      export def Varargs(a1: string, ...l: list<string>): string
         return a1 .. l[0] .. l[1]
       enddef
    END
***************
*** 1630,1652 ****
    var save_rtp = &rtp
    exe 'set rtp^=' .. getcwd() .. '/Xdir'
  
!   assert_equal('test', g:some#gettest())
    assert_equal('name', g:some#name)
    assert_equal('value', g:some#dict.key)
    g:some#other = 'other'
    assert_equal('other', g:some#other)
  
!   assert_equal('abc', some#varargs('a', 'b', 'c'))
  
    # upper case script name works
    lines =<< trim END
       vim9script
!      def Other#getOther(): string
         return 'other'
       enddef
    END
    writefile(lines, 'Xdir/autoload/Other.vim')
!   assert_equal('other', g:Other#getOther())
  
    delete('Xdir', 'rf')
    &rtp = save_rtp
--- 1630,1652 ----
    var save_rtp = &rtp
    exe 'set rtp^=' .. getcwd() .. '/Xdir'
  
!   assert_equal('test', g:some#Gettest())
    assert_equal('name', g:some#name)
    assert_equal('value', g:some#dict.key)
    g:some#other = 'other'
    assert_equal('other', g:some#other)
  
!   assert_equal('abc', some#Varargs('a', 'b', 'c'))
  
    # upper case script name works
    lines =<< trim END
       vim9script
!      export def GetOther(): string
         return 'other'
       enddef
    END
    writefile(lines, 'Xdir/autoload/Other.vim')
!   assert_equal('other', g:Other#GetOther())
  
    delete('Xdir', 'rf')
    &rtp = save_rtp
***************
*** 2020,2033 ****
  
  def Test_autoload_name_wrong()
    var lines =<< trim END
-      vim9script
       def Xscriptname#Func()
       enddef
    END
    writefile(lines, 'Xscriptname.vim')
!   v9.CheckScriptFailure(lines, 'E1263:')
! 
    delete('Xscriptname.vim')
  enddef
  
  def Test_import_autoload_postponed()
--- 2020,2042 ----
  
  def Test_autoload_name_wrong()
    var lines =<< trim END
       def Xscriptname#Func()
       enddef
    END
    writefile(lines, 'Xscriptname.vim')
!   v9.CheckScriptFailure(lines, 'E746:')
    delete('Xscriptname.vim')
+ 
+   mkdir('Xdir/autoload', 'p')
+   lines =<< trim END
+      vim9script
+      def somescript#Func()
+      enddef
+   END
+   writefile(lines, 'Xdir/autoload/somescript.vim')
+   assert_fails('source Xdir/autoload/somescript.vim', 'E1263:')
+ 
+   delete('Xdir', 'rf')
  enddef
  
  def Test_import_autoload_postponed()
***************
*** 2202,2208 ****
  
    var lines =<< trim END
       vim9script
!      def debugit#test(): string
         return 'debug'
       enddef
    END
--- 2211,2217 ----
  
    var lines =<< trim END
       vim9script
!      export def Test(): string
         return 'debug'
       enddef
    END
***************
*** 2210,2216 ****
  
    lines =<< trim END
       vim9script
!      def profileit#test(): string
         return 'profile'
       enddef
    END
--- 2219,2225 ----
  
    lines =<< trim END
       vim9script
!      export def Test(): string
         return 'profile'
       enddef
    END
***************
*** 2218,2227 ****
  
    lines =<< trim END
      vim9script
!     assert_equal('debug', debugit#test())
!     disass debugit#test
!     assert_equal('profile', profileit#test())
!     disass profileit#test
    END
    v9.CheckScriptSuccess(lines)
  
--- 2227,2236 ----
  
    lines =<< trim END
      vim9script
!     assert_equal('debug', debugit#Test())
!     disass debugit#Test
!     assert_equal('profile', profileit#Test())
!     disass profileit#Test
    END
    v9.CheckScriptSuccess(lines)
  
***************
*** 2233,2239 ****
  def Test_vim9_aucmd_autoload()
    var lines =<< trim END
       vim9script
!      def foo#test()
           echomsg getreg('"')
       enddef
    END
--- 2242,2248 ----
  def Test_vim9_aucmd_autoload()
    var lines =<< trim END
       vim9script
!      export def Test()
           echomsg getreg('"')
       enddef
    END
***************
*** 2243,2249 ****
    var save_rtp = &rtp
    exe 'set rtp^=' .. getcwd() .. '/Xdir'
    augroup test
!     autocmd TextYankPost * call foo#test()
    augroup END
  
    normal Y
--- 2252,2258 ----
    var save_rtp = &rtp
    exe 'set rtp^=' .. getcwd() .. '/Xdir'
    augroup test
!     autocmd TextYankPost * call foo#Test()
    augroup END
  
    normal Y
*** ../vim-8.2.4263/src/testdir/test_vim9_func.vim      2022-01-30 
15:28:26.646294975 +0000
--- src/testdir/test_vim9_func.vim      2022-01-30 18:33:23.265799981 +0000
***************
*** 46,52 ****
  
    var lines =<< trim END
        vim9script
!       def script#OnlyCompiled()
          g:runtime = 'yes'
          invalid
        enddef
--- 46,52 ----
  
    var lines =<< trim END
        vim9script
!       export def OnlyCompiled()
          g:runtime = 'yes'
          invalid
        enddef
***************
*** 114,120 ****
  
    var lines =<< trim END
        vim9script
!       def scriptX#Function()
          # comment
          g:runtime = 'yes'
        enddef
--- 114,120 ----
  
    var lines =<< trim END
        vim9script
!       export def NoFunction()
          # comment
          g:runtime = 'yes'
        enddef
***************
*** 126,132 ****
    lines =<< trim END
        call script#Function()
    END
!   v9.CheckScriptFailure(lines, 'E746:', 2)
  
    &rtp = save_rtp
    delete(dir, 'rf')
--- 126,132 ----
    lines =<< trim END
        call script#Function()
    END
!   v9.CheckScriptFailure(lines, 'E117:', 1)
  
    &rtp = save_rtp
    delete(dir, 'rf')
*** ../vim-8.2.4263/src/testdir/test_vim9_script.vim    2022-01-29 
21:45:30.481921547 +0000
--- src/testdir/test_vim9_script.vim    2022-01-30 18:38:52.108877327 +0000
***************
*** 3078,3084 ****
  
    var lines =<< trim END
        vim9script noclear
!       def script#autoloaded()
        enddef
        def Broken()
          var x: any = ''
--- 3078,3084 ----
  
    var lines =<< trim END
        vim9script noclear
!       export def Autoloaded()
        enddef
        def Broken()
          var x: any = ''
***************
*** 3091,3097 ****
    lines =<< trim END
        vim9script
        def CallAutoloaded()
!         script#autoloaded()
        enddef
  
        function Legacy()
--- 3091,3097 ----
    lines =<< trim END
        vim9script
        def CallAutoloaded()
!         script#Autoloaded()
        enddef
  
        function Legacy()
***************
*** 3196,3202 ****
  
    let lines =<< trim END
      vim9script
!     def script#func()
      enddef
    END
    call mkdir('Xdir/autoload', 'p')
--- 3196,3202 ----
  
    let lines =<< trim END
      vim9script
!     export def Func()
      enddef
    END
    call mkdir('Xdir/autoload', 'p')
***************
*** 3206,3212 ****
        vim9script
        set cpo+=M
        exe 'set rtp^=' .. getcwd() .. '/Xdir'
!       au CmdlineEnter : ++once timer_start(0, (_) => script#func())
        setline(1, 'some text')
    END
    call writefile(lines, 'XTest_redraw_cpo')
--- 3206,3212 ----
        vim9script
        set cpo+=M
        exe 'set rtp^=' .. getcwd() .. '/Xdir'
!       au CmdlineEnter : ++once timer_start(0, (_) => script#Func())
        setline(1, 'some text')
    END
    call writefile(lines, 'XTest_redraw_cpo')
*** ../vim-8.2.4263/src/version.c       2022-01-30 18:00:22.703274483 +0000
--- src/version.c       2022-01-30 18:11:41.869308279 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4264,
  /**/

-- 
ARTHUR:    Be quiet!  I order you to shut up.
OLD WOMAN: Order, eh -- who does he think he is?
ARTHUR:    I am your king!
OLD WOMAN: Well, I didn't vote for you.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// 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/20220130184120.B22041C1918%40moolenaar.net.

Raspunde prin e-mail lui