Merge pull request #8974 from janlazo/vim-8.0.1377

This commit is contained in:
Justin M. Keyes 2018-09-11 08:33:21 +02:00 committed by GitHub
commit 036051b218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 11 deletions

View File

@ -2076,7 +2076,11 @@ static char_u *get_lval(char_u *const name, typval_T *const rettv,
return p; return p;
} }
v = find_var(lp->ll_name, lp->ll_name_len, &ht, flags & GLV_NO_AUTOLOAD); // Only pass &ht when we would write to the variable, it prevents autoload
// as well.
v = find_var(lp->ll_name, lp->ll_name_len,
(flags & GLV_READ_ONLY) ? NULL : &ht,
flags & GLV_NO_AUTOLOAD);
if (v == NULL && !quiet) { if (v == NULL && !quiet) {
emsgf(_("E121: Undefined variable: %.*s"), emsgf(_("E121: Undefined variable: %.*s"),
(int)lp->ll_name_len, lp->ll_name); (int)lp->ll_name_len, lp->ll_name);
@ -18326,9 +18330,9 @@ varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE
return vimvars[idx].vv_nr; return vimvars[idx].vv_nr;
} }
/* // Get string v: variable value. Uses a static buffer, can only be used once.
* Get string v: variable value. Uses a static buffer, can only be used once. // If the String variable has never been set, return an empty string.
*/ // Never returns NULL;
char_u *get_vim_var_str(int idx) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET char_u *get_vim_var_str(int idx) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET
{ {
return (char_u *)tv_get_string(&vimvars[idx].vv_tv); return (char_u *)tv_get_string(&vimvars[idx].vv_tv);
@ -19820,7 +19824,7 @@ void ex_function(exarg_T *eap)
// s:func script-local function name // s:func script-local function name
// g:func global function name, same as "func" // g:func global function name, same as "func"
p = eap->arg; p = eap->arg;
name = trans_function_name(&p, eap->skip, 0, &fudi, NULL); name = trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL);
paren = (vim_strchr(p, '(') != NULL); paren = (vim_strchr(p, '(') != NULL);
if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) { if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) {
/* /*
@ -20364,7 +20368,7 @@ trans_function_name(
} }
// Note that TFN_ flags use the same values as GLV_ flags. // Note that TFN_ flags use the same values as GLV_ flags.
end = get_lval((char_u *)start, NULL, &lv, false, skip, flags, end = get_lval((char_u *)start, NULL, &lv, false, skip, flags | GLV_READ_ONLY,
lead > 2 ? 0 : FNE_CHECK_START); lead > 2 ? 0 : FNE_CHECK_START);
if (end == start) { if (end == start) {
if (!skip) if (!skip)

View File

@ -0,0 +1,7 @@
let g:loaded_foo_vim += 1
let foo#bar = {}
func foo#bar.echo()
let g:called_foo_bar_echo += 1
endfunc

View File

@ -0,0 +1 @@
" used by Test_globpath()

View File

@ -0,0 +1 @@
" used by Test_globpath()

View File

@ -0,0 +1,3 @@
let g:loaded_sourced_vim += 1
func! sourced#something()
endfunc

View File

@ -0,0 +1,17 @@
" Tests for autoload
set runtimepath=./sautest
func Test_autoload_dict_func()
let g:loaded_foo_vim = 0
let g:called_foo_bar_echo = 0
call g:foo#bar.echo()
call assert_equal(1, g:loaded_foo_vim)
call assert_equal(1, g:called_foo_bar_echo)
endfunc
func Test_source_autoload()
let g:loaded_sourced_vim = 0
source sautest/autoload/sourced.vim
call assert_equal(1, g:loaded_sourced_vim)
endfunc

View File

@ -17,6 +17,7 @@ function Test_glob()
call assert_equal("", glob('Xxx\{')) call assert_equal("", glob('Xxx\{'))
call assert_equal("", glob('Xxx\$')) call assert_equal("", glob('Xxx\$'))
w! Xxx{ w! Xxx{
" } to fix highlighting
w! Xxx\$ w! Xxx\$
call assert_equal("Xxx{", glob('Xxx\{')) call assert_equal("Xxx{", glob('Xxx\{'))
call assert_equal("Xxx$", glob('Xxx\$')) call assert_equal("Xxx$", glob('Xxx\$'))
@ -25,9 +26,8 @@ function Test_glob()
endfunction endfunction
function Test_globpath() function Test_globpath()
let slash = (!exists('+shellslash') || &shellslash) ? '/' : '\' call assert_equal(expand("sautest/autoload/globone.vim\nsautest/autoload/globtwo.vim"),
call assert_equal('sautest'.slash.'autoload'.slash.'footest.vim', \ globpath('sautest/autoload', 'glob*.vim'))
\ globpath('sautest/autoload', '*.vim')) call assert_equal([expand('sautest/autoload/globone.vim'), expand('sautest/autoload/globtwo.vim')],
call assert_equal(['sautest'.slash.'autoload'.slash.'footest.vim'], \ globpath('sautest/autoload', 'glob*.vim', 0, 1))
\ globpath('sautest/autoload', '*.vim', 0, 1))
endfunction endfunction