Patch 8.2.4264

12 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 30, 2022, 1:41:26 PM1/30/22
to vim...@googlegroups.com

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 -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Jan 30, 2022, 2:18:13 PM1/30/22
to vim...@googlegroups.com

On 31-Jan-2022 05:41, Bram Moolenaar wrote:
> 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
>
>
>
After this patch, mingw64 (gcc 11.2.0) throws this warning:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD userfunc.c -o
gobjnative/userfunc.o
userfunc.c: In function 'define_function':
userfunc.c:4833:14: warning: 'saved_did_emsg' may be used uninitialized
in this function [-Wmaybe-uninitialized]
 4833 |     did_emsg |= saved_did_emsg;
      |              ^~
</snip>

The attached patch tries to fix it.

By the way, are we sure that line 4833 (did_emsg |= saved_did_emsg) is
correct? Shouldn't it be: did_emsg = save_did_emsg?

Cheers
John
userfunc.c.8.2.4264.patch

Bram Moolenaar

unread,
Jan 30, 2022, 3:01:48 PM1/30/22
to vim...@googlegroups.com, John Marriott

John Marriott wrote:

> On 31-Jan-2022 05:41, Bram Moolenaar wrote:
> > 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
> >
> >
> >
> After this patch, mingw64 (gcc 11.2.0) throws this warning:
> <snip>
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
> -pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
> -fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD userfunc.c -o
> gobjnative/userfunc.o
> userfunc.c: In function 'define_function':
> userfunc.c:4833:14: warning: 'saved_did_emsg' may be used uninitialized
> in this function [-Wmaybe-uninitialized]
>  4833 |     did_emsg |= saved_did_emsg;
>       |              ^~
> </snip>
>
> The attached patch tries to fix it.

I saw your patch only after sending out patch 8.2.4266. The effect
should be the same.

> By the way, are we sure that line 4833 (did_emsg |= saved_did_emsg) is
> correct? Shouldn't it be: did_emsg = save_did_emsg?

We don't want to reset did_emsg here. It's a corner case anyway, the
comment mentions "magic braces":

// An error in a function call during evaluation of an expression in magic
// braces should not cause the function not to be defined.

I'm not sure this is true, we usually abort when an error is detected.
But I don't like to change old behavior unless we know why it was done
that way.


--
DENNIS: You can't expect to wield supreme executive power just 'cause some
watery tart threw a sword at you!

John Marriott

unread,
Jan 30, 2022, 3:11:59 PM1/30/22
to Bram Moolenaar, vim...@googlegroups.com


On 31-Jan-2022 07:01, Bram Moolenaar wrote:
>
> I saw your patch only after sending out patch 8.2.4266. The effect
> should be the same.
>
>> By the way, are we sure that line 4833 (did_emsg |= saved_did_emsg) is
>> correct? Shouldn't it be: did_emsg = save_did_emsg?
> We don't want to reset did_emsg here. It's a corner case anyway, the
> comment mentions "magic braces":
>
> // An error in a function call during evaluation of an expression in magic
> // braces should not cause the function not to be defined.
>
> I'm not sure this is true, we usually abort when an error is detected.
> But I don't like to change old behavior unless we know why it was done
> that way.
>
>
No worries.
Reply all
Reply to author
Forward
0 new messages