mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -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:
parent
c785b9a7f4
commit
3b74b6b4bb
@ -1343,7 +1343,7 @@ do_source(
|
|||||||
|
|
||||||
// Allocate the local script variables to use for this script.
|
// Allocate the local script variables to use for this script.
|
||||||
new_script_vars(script_items.ga_len);
|
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_imports, sizeof(imported_T), 10);
|
||||||
ga_init2(&si->sn_type_list, sizeof(type_T), 10);
|
ga_init2(&si->sn_type_list, sizeof(type_T), 10);
|
||||||
# ifdef FEAT_PROFILE
|
# ifdef FEAT_PROFILE
|
||||||
|
@ -109,6 +109,41 @@ def Test_assignment()
|
|||||||
call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
|
call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
|
||||||
enddef
|
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()
|
def Test_assignment_list()
|
||||||
let list1: list<bool> = [false, true, false]
|
let list1: list<bool> = [false, true, false]
|
||||||
let list2: list<number> = [1, 2, 3]
|
let list2: list<number> = [1, 2, 3]
|
||||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1012,
|
||||||
/**/
|
/**/
|
||||||
1011,
|
1011,
|
||||||
/**/
|
/**/
|
||||||
|
@ -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))
|
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;
|
break;
|
||||||
|
|
||||||
if (*p != ':')
|
if (*p != ':')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user