0
0
mirror of https://github.com/vim/vim.git synced 2025-07-24 10:45:12 -04:00

patch 8.2.1012: Vim9: cannot declare single character script variables

Problem:    Vim9: cannot declare single character script variables.
Solution:   Don't see "b:", "s:", etc. as namespace.  Fix item size of
            sn_var_vals.
This commit is contained in:
Bram Moolenaar 2020-06-19 19:01:43 +02:00
parent c785b9a7f4
commit 3b74b6b4bb
4 changed files with 39 additions and 2 deletions

View File

@ -1343,7 +1343,7 @@ do_source(
// Allocate the local script variables to use for this script.
new_script_vars(script_items.ga_len);
ga_init2(&si->sn_var_vals, sizeof(typval_T), 10);
ga_init2(&si->sn_var_vals, sizeof(svar_T), 10);
ga_init2(&si->sn_imports, sizeof(imported_T), 10);
ga_init2(&si->sn_type_list, sizeof(type_T), 10);
# ifdef FEAT_PROFILE

View File

@ -109,6 +109,41 @@ def Test_assignment()
call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
enddef
def Test_vim9_single_char_vars()
let lines =<< trim END
vim9script
" single character variable declarations work
let a: string
let b: number
let l: list<any>
let s: string
let t: number
let v: number
let w: number
" script-local variables can be used without s: prefix
a = 'script-a'
b = 111
l = [1, 2, 3]
s = 'script-s'
t = 222
v = 333
w = 444
assert_equal('script-a', a)
assert_equal(111, b)
assert_equal([1, 2, 3], l)
assert_equal('script-s', s)
assert_equal(222, t)
assert_equal(333, v)
assert_equal(444, w)
END
writefile(lines, 'Xsinglechar')
source Xsinglechar
delete('Xsinglechar')
enddef
def Test_assignment_list()
let list1: list<bool> = [false, true, false]
let list2: list<number> = [1, 2, 3]

View File

@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1012,
/**/
1011,
/**/

View File

@ -471,7 +471,7 @@ vim9_declare_scriptvar(exarg_T *eap, char_u *arg)
}
for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p))
if (*p == ':' && p != arg + 1)
if (*p == ':' && (VIM_ISWHITE(p[1]) || p != arg + 1))
break;
if (*p != ':')