mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Problem: Vim9: cannot assign to single letter variable with type. Solution: Exclude the colon from the variable name. (closes #6647)
This commit is contained in:
11
src/eval.c
11
src/eval.c
@@ -820,7 +820,15 @@ get_lval(
|
|||||||
{
|
{
|
||||||
lp->ll_name = name;
|
lp->ll_name = name;
|
||||||
|
|
||||||
if (in_vim9script() && *p == ':')
|
if (in_vim9script())
|
||||||
|
{
|
||||||
|
// "a: type" is declaring variable "a" with a type, not "a:".
|
||||||
|
if (p == name + 2 && p[-1] == ':')
|
||||||
|
{
|
||||||
|
--p;
|
||||||
|
lp->ll_name_end = p;
|
||||||
|
}
|
||||||
|
if (*p == ':')
|
||||||
{
|
{
|
||||||
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
|
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
|
||||||
char_u *tp = skipwhite(p + 1);
|
char_u *tp = skipwhite(p + 1);
|
||||||
@@ -830,6 +838,7 @@ get_lval(
|
|||||||
lp->ll_name_end = tp;
|
lp->ll_name_end = tp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Without [idx] or .key we are done.
|
// Without [idx] or .key we are done.
|
||||||
if ((*p != '[' && *p != '.') || lp->ll_name == NULL)
|
if ((*p != '[' && *p != '.') || lp->ll_name == NULL)
|
||||||
|
@@ -449,6 +449,17 @@ def Test_assignment_vim9script()
|
|||||||
@+ = 'plus'
|
@+ = 'plus'
|
||||||
assert_equal('plus', @+)
|
assert_equal('plus', @+)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let a: number = 123
|
||||||
|
assert_equal(123, a)
|
||||||
|
let s: string = 'yes'
|
||||||
|
assert_equal('yes', s)
|
||||||
|
let b: number = 42
|
||||||
|
assert_equal(42, b)
|
||||||
|
let w: number = 43
|
||||||
|
assert_equal(43, w)
|
||||||
|
let t: number = 44
|
||||||
|
assert_equal(44, t)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1387,
|
||||||
/**/
|
/**/
|
||||||
1386,
|
1386,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user