patch 8.2.1320: Vim9: cannot declare some single letter variables
Problem: Vim9: cannot declare some single letter variables.
Solution: Do not recognize a colon for a namespace for single letter
variables. (closes #6547)
This commit is contained in:
@ -109,6 +109,9 @@ def Test_assignment()
|
|||||||
call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
|
call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
|
||||||
&ts = 8
|
&ts = 8
|
||||||
|
|
||||||
|
call CheckDefFailure(['let s:var = 123'], 'E1101:')
|
||||||
|
call CheckDefFailure(['let s:var: number'], 'E1101:')
|
||||||
|
|
||||||
g:inc_counter += 1
|
g:inc_counter += 1
|
||||||
assert_equal(2, g:inc_counter)
|
assert_equal(2, g:inc_counter)
|
||||||
|
|
||||||
@ -136,6 +139,28 @@ def Test_assignment()
|
|||||||
assert_equal('noneagain', v:errmsg)
|
assert_equal('noneagain', v:errmsg)
|
||||||
call CheckDefFailure(['v:errmsg += "more"'], 'E1013:')
|
call CheckDefFailure(['v:errmsg += "more"'], 'E1013:')
|
||||||
call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
|
call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
|
||||||
|
|
||||||
|
# single letter variables
|
||||||
|
a = 123
|
||||||
|
assert_equal(123, a)
|
||||||
|
let b: number
|
||||||
|
b = 123
|
||||||
|
assert_equal(123, b)
|
||||||
|
let g: number
|
||||||
|
g = 123
|
||||||
|
assert_equal(123, g)
|
||||||
|
let s: number
|
||||||
|
s = 123
|
||||||
|
assert_equal(123, s)
|
||||||
|
let t: number
|
||||||
|
t = 123
|
||||||
|
assert_equal(123, t)
|
||||||
|
let v: number
|
||||||
|
v = 123
|
||||||
|
assert_equal(123, v)
|
||||||
|
let w: number
|
||||||
|
w = 123
|
||||||
|
assert_equal(123, w)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_vim9_single_char_vars()
|
def Test_vim9_single_char_vars()
|
||||||
|
|||||||
@ -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 */
|
||||||
|
/**/
|
||||||
|
1320,
|
||||||
/**/
|
/**/
|
||||||
1319,
|
1319,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
@ -5237,7 +5237,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STRNCMP(var_start, "g:", 2) == 0)
|
else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0)
|
||||||
{
|
{
|
||||||
dest = dest_global;
|
dest = dest_global;
|
||||||
if (is_decl)
|
if (is_decl)
|
||||||
@ -5246,7 +5246,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STRNCMP(var_start, "b:", 2) == 0)
|
else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0)
|
||||||
{
|
{
|
||||||
dest = dest_buffer;
|
dest = dest_buffer;
|
||||||
if (is_decl)
|
if (is_decl)
|
||||||
@ -5255,7 +5255,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STRNCMP(var_start, "w:", 2) == 0)
|
else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0)
|
||||||
{
|
{
|
||||||
dest = dest_window;
|
dest = dest_window;
|
||||||
if (is_decl)
|
if (is_decl)
|
||||||
@ -5264,7 +5264,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STRNCMP(var_start, "t:", 2) == 0)
|
else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0)
|
||||||
{
|
{
|
||||||
dest = dest_tab;
|
dest = dest_tab;
|
||||||
if (is_decl)
|
if (is_decl)
|
||||||
@ -5273,7 +5273,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STRNCMP(var_start, "v:", 2) == 0)
|
else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0)
|
||||||
{
|
{
|
||||||
typval_T *vtv;
|
typval_T *vtv;
|
||||||
int di_flags;
|
int di_flags;
|
||||||
@ -5337,14 +5337,18 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STRNCMP(var_start, "s:", 2) == 0
|
else if ((varlen > 1 && STRNCMP(var_start, "s:", 2) == 0)
|
||||||
|| lookup_script(var_start, varlen) == OK
|
|| lookup_script(var_start, varlen) == OK
|
||||||
|| find_imported(var_start, varlen, cctx) != NULL)
|
|| find_imported(var_start, varlen, cctx) != NULL)
|
||||||
{
|
{
|
||||||
dest = dest_script;
|
dest = dest_script;
|
||||||
if (is_decl)
|
if (is_decl)
|
||||||
{
|
{
|
||||||
semsg(_("E1054: Variable already declared in the script: %s"),
|
if ((varlen > 1 && STRNCMP(var_start, "s:", 2) == 0))
|
||||||
|
semsg(_("E1101: Cannot declare a script variable in a function: %s"),
|
||||||
|
name);
|
||||||
|
else
|
||||||
|
semsg(_("E1054: Variable already declared in the script: %s"),
|
||||||
name);
|
name);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user