Skip to content

Commit a4252b3

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 08d4327 + 17f700a commit a4252b3

File tree

13 files changed

+184
-21
lines changed

13 files changed

+184
-21
lines changed

src/dict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
10731073
&& HI2DI(hi2)->di_tv.v_type == VAR_FUNC
10741074
&& var_wrong_func_name(hi2->hi_key, di1 == NULL))
10751075
break;
1076-
if (!valid_varname(hi2->hi_key))
1076+
if (!valid_varname(hi2->hi_key, TRUE))
10771077
break;
10781078
}
10791079
if (di1 == NULL)

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ get_lval(
10491049
wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
10501050
&& rettv->v_type == VAR_FUNC
10511051
&& var_wrong_func_name(key, lp->ll_di == NULL))
1052-
|| !valid_varname(key);
1052+
|| !valid_varname(key, TRUE);
10531053
if (len != -1)
10541054
key[len] = prevval;
10551055
if (wrong)

src/evalvars.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,8 +3197,10 @@ set_var_const(
31973197
goto failed;
31983198
}
31993199

3200-
// Make sure the variable name is valid.
3201-
if (!valid_varname(varname))
3200+
// Make sure the variable name is valid. In Vim9 script an autoload
3201+
// variable must be prefixed with "g:".
3202+
if (!valid_varname(varname, !vim9script
3203+
|| STRNCMP(name, "g:", 2) == 0))
32023204
goto failed;
32033205

32043206
di = alloc(sizeof(dictitem_T) + STRLEN(varname));
@@ -3351,17 +3353,17 @@ value_check_lock(int lock, char_u *name, int use_gettext)
33513353
}
33523354

33533355
/*
3354-
* Check if a variable name is valid.
3356+
* Check if a variable name is valid. When "autoload" is true "#" is allowed.
33553357
* Return FALSE and give an error if not.
33563358
*/
33573359
int
3358-
valid_varname(char_u *varname)
3360+
valid_varname(char_u *varname, int autoload)
33593361
{
33603362
char_u *p;
33613363

33623364
for (p = varname; *p != NUL; ++p)
33633365
if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
3364-
&& *p != AUTOLOAD_CHAR)
3366+
&& !(autoload && *p == AUTOLOAD_CHAR))
33653367
{
33663368
semsg(_(e_illvar), varname);
33673369
return FALSE;

src/ex_eval.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ discard_exception(except_T *excp, int was_finished)
606606
{
607607
char_u *saved_IObuff;
608608

609+
if (current_exception == excp)
610+
current_exception = NULL;
609611
if (excp == NULL)
610612
{
611613
internal_error("discard_exception()");
@@ -654,10 +656,7 @@ discard_exception(except_T *excp, int was_finished)
654656
discard_current_exception(void)
655657
{
656658
if (current_exception != NULL)
657-
{
658659
discard_exception(current_exception, FALSE);
659-
current_exception = NULL;
660-
}
661660
did_throw = FALSE;
662661
need_rethrow = FALSE;
663662
}
@@ -2284,8 +2283,8 @@ cleanup_conditionals(
22842283
// Cancel the pending exception. This is in the
22852284
// finally clause, so that the stack of the
22862285
// caught exceptions is not involved.
2287-
discard_exception((except_T *)
2288-
cstack->cs_exception[idx],
2286+
discard_exception(
2287+
(except_T *)cstack->cs_exception[idx],
22892288
FALSE);
22902289
}
22912290
else

src/proto/evalvars.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int var_check_lock(int flags, char_u *name, int use_gettext);
7575
int var_check_fixed(int flags, char_u *name, int use_gettext);
7676
int var_wrong_func_name(char_u *name, int new_var);
7777
int value_check_lock(int lock, char_u *name, int use_gettext);
78-
int valid_varname(char_u *varname);
78+
int valid_varname(char_u *varname, int autoload);
7979
void reset_v_option_vars(void);
8080
void assert_error(garray_T *gap);
8181
int var_exists(char_u *var);

src/testdir/test_startup.vim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,53 @@ func Test_t_arg()
743743
call delete('Xfile1')
744744
endfunc
745745

746+
" Test the '-T' argument which sets the 'term' option.
747+
func Test_T_arg()
748+
CheckNotGui
749+
let after =<< trim [CODE]
750+
call writefile([&term], "Xtest_T_arg")
751+
qall
752+
[CODE]
753+
754+
for t in ['builtin_dumb', 'builtin_ansi']
755+
if RunVim([], after, '-T ' .. t)
756+
let lines = readfile('Xtest_T_arg')
757+
call assert_equal([t], lines)
758+
endif
759+
endfor
760+
761+
call delete('Xtest_T_arg')
762+
endfunc
763+
764+
" Test the '-x' argument to read/write encrypted files.
765+
func Test_x_arg()
766+
CheckRunVimInTerminal
767+
CheckFeature cryptv
768+
769+
" Create an encrypted file Xtest_x_arg.
770+
let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
771+
call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
772+
call term_sendkeys(buf, "foo\n")
773+
call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
774+
call term_sendkeys(buf, "foo\n")
775+
call WaitForAssert({-> assert_match(' All$', term_getline(buf, 10))})
776+
call term_sendkeys(buf, "itest\<Esc>:w\<Enter>")
777+
call WaitForAssert({-> assert_match('"Xtest_x_arg" \[New\]\[blowfish2\] 1L, 5B written',
778+
\ term_getline(buf, 10))})
779+
call StopVimInTerminal(buf)
780+
781+
" Read the encrypted file and check that it contains the expected content "test"
782+
let buf = RunVimInTerminal('-n -x Xtest_x_arg', #{rows: 10, wait_for_ruler: 0})
783+
call WaitForAssert({-> assert_match('^Enter encryption key: ', term_getline(buf, 10))})
784+
call term_sendkeys(buf, "foo\n")
785+
call WaitForAssert({-> assert_match('^Enter same key again: ', term_getline(buf, 10))})
786+
call term_sendkeys(buf, "foo\n")
787+
call WaitForAssert({-> assert_match('^test', term_getline(buf, 1))})
788+
call StopVimInTerminal(buf)
789+
790+
call delete('Xtest_x_arg')
791+
endfunc
792+
746793
" Test for entering the insert mode on startup
747794
func Test_start_insertmode()
748795
let before =<< trim [CODE]

src/testdir/test_vim9_disassemble.vim

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def s:ScriptFuncLoad(arg: string)
2323
echo s:scriptvar
2424
echo g:globalvar
2525
echo get(g:, "global")
26+
echo g:auto#var
2627
echo b:buffervar
2728
echo get(b:, "buffer")
2829
echo w:windowvar
@@ -68,8 +69,14 @@ def Test_disassemble_load()
6869
'echo get(g:, "global")\_s*' ..
6970
'\d\+ LOAD g:\_s*' ..
7071
'\d\+ PUSHS "global"\_s*' ..
71-
'\d\+ BCALL get(argc 2).*' ..
72-
' LOADB b:buffervar.*' ..
72+
'\d\+ BCALL get(argc 2)\_s*' ..
73+
'\d\+ ECHO 1\_s*' ..
74+
'echo g:auto#var\_s*' ..
75+
'\d\+ LOADAUTO g:auto#var\_s*' ..
76+
'\d\+ ECHO 1\_s*' ..
77+
'echo b:buffervar\_s*' ..
78+
'\d\+ LOADB b:buffervar\_s*' ..
79+
'\d\+ ECHO 1\_s*' ..
7380
'echo get(b:, "buffer")\_s*' ..
7481
'\d\+ LOAD b:\_s*' ..
7582
'\d\+ PUSHS "buffer"\_s*' ..
@@ -197,6 +204,7 @@ def s:ScriptFuncStore()
197204
v:char = 'abc'
198205
s:scriptvar = 'sv'
199206
g:globalvar = 'gv'
207+
g:auto#var = 'av'
200208
b:buffervar = 'bv'
201209
w:windowvar = 'wv'
202210
t:tabpagevar = 'tv'
@@ -220,6 +228,8 @@ def Test_disassemble_store()
220228
' STORES s:scriptvar in .*test_vim9_disassemble.vim.*' ..
221229
'g:globalvar = ''gv''.*' ..
222230
' STOREG g:globalvar.*' ..
231+
'g:auto#var = ''av''.*' ..
232+
' STOREAUTO g:auto#var.*' ..
223233
'b:buffervar = ''bv''.*' ..
224234
' STOREB b:buffervar.*' ..
225235
'w:windowvar = ''wv''.*' ..

src/testdir/test_vim9_script.vim

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2779,8 +2779,42 @@ def Test_vim9_copen()
27792779
quit
27802780
enddef
27812781

2782-
" test using a vim9script that is auto-loaded from an autocmd
2782+
" test using an auto-loaded function and variable
27832783
def Test_vim9_autoload()
2784+
var lines =<< trim END
2785+
vim9script
2786+
def some#gettest(): string
2787+
return 'test'
2788+
enddef
2789+
g:some#name = 'name'
2790+
END
2791+
2792+
mkdir('Xdir/autoload', 'p')
2793+
writefile(lines, 'Xdir/autoload/some.vim')
2794+
var save_rtp = &rtp
2795+
exe 'set rtp^=' .. getcwd() .. '/Xdir'
2796+
2797+
assert_equal('test', g:some#gettest())
2798+
assert_equal('name', g:some#name)
2799+
g:some#other = 'other'
2800+
assert_equal('other', g:some#other)
2801+
2802+
# upper case script name works
2803+
lines =<< trim END
2804+
vim9script
2805+
def Other#getOther(): string
2806+
return 'other'
2807+
enddef
2808+
END
2809+
writefile(lines, 'Xdir/autoload/Other.vim')
2810+
assert_equal('other', g:Other#getOther())
2811+
2812+
delete('Xdir', 'rf')
2813+
&rtp = save_rtp
2814+
enddef
2815+
2816+
" test using a vim9script that is auto-loaded from an autocmd
2817+
def Test_vim9_aucmd_autoload()
27842818
var lines =<< trim END
27852819
vim9script
27862820
def foo#test()
@@ -2842,6 +2876,12 @@ def Test_vim9_autoload_error()
28422876
delete('Xdidit')
28432877
delete('Xscript')
28442878
delete('Xruntime', 'rf')
2879+
2880+
lines =<< trim END
2881+
vim9script
2882+
var foo#bar = 'asdf'
2883+
END
2884+
CheckScriptFailure(lines, 'E461: Illegal variable name: foo#bar', 2)
28452885
enddef
28462886

28472887
def Test_script_var_in_autocmd()

src/userfunc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,8 +2654,18 @@ trans_function_name(
26542654
goto theend;
26552655
}
26562656

2657-
// In Vim9 script a user function is script-local by default.
2657+
// In Vim9 script a user function is script-local by default, unless it
2658+
// starts with a lower case character: dict.func().
26582659
vim9script = ASCII_ISUPPER(*start) && in_vim9script();
2660+
if (vim9script)
2661+
{
2662+
char_u *p;
2663+
2664+
// SomeScript#func() is a global function.
2665+
for (p = start; *p != NUL && *p != '('; ++p)
2666+
if (*p == AUTOLOAD_CHAR)
2667+
vim9script = FALSE;
2668+
}
26592669

26602670
/*
26612671
* Copy the function name to allocated memory.

src/version.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,14 @@ static char *(features[]) =
765765

766766
static int included_patches[] =
767767
{ /* Add new patch number below this line */
768+
/**/
769+
2164,
770+
/**/
771+
2163,
772+
/**/
773+
2162,
774+
/**/
775+
2161,
768776
/**/
769777
2160,
770778
/**/

0 commit comments

Comments
 (0)