Skip to content

Commit 3f32788

Browse files
committed
patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Problem: Vim9: cannot use a normal list name to store function refs. Solution: Allow a lower case name if it is indexed.
1 parent 8863bda commit 3f32788

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/testdir/test_vim9_assign.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def Test_assignment()
7272
CheckDefFailure(['var lambda = () => "lambda"'], 'E704:')
7373
CheckScriptFailure(['var x = "x"'], 'E1124:')
7474

75+
# lower case name is OK for a list
76+
var lambdaLines =<< trim END
77+
var lambdaList: list<func> = [Test_syntax]
78+
lambdaList[0] = () => "lambda"
79+
END
80+
CheckDefAndScriptSuccess(lambdaLines)
81+
7582
var nr: number = 1234
7683
CheckDefFailure(['var nr: number = "asdf"'], 'E1012:')
7784

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2618,
753755
/**/
754756
2617,
755757
/**/

src/vim9compile.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5832,11 +5832,13 @@ compile_lhs(
58325832
return FAIL;
58335833
}
58345834

5835-
// new local variable
5835+
// Check the name is valid for a funcref.
58365836
if ((lhs->lhs_type->tt_type == VAR_FUNC
58375837
|| lhs->lhs_type->tt_type == VAR_PARTIAL)
5838-
&& var_wrong_func_name(lhs->lhs_name, TRUE))
5838+
&& var_wrong_func_name(lhs->lhs_name, TRUE))
58395839
return FAIL;
5840+
5841+
// New local variable.
58405842
lhs->lhs_lvar = reserve_local(cctx, var_start, lhs->lhs_varlen,
58415843
cmdidx == CMD_final || cmdidx == CMD_const, lhs->lhs_type);
58425844
if (lhs->lhs_lvar == NULL)
@@ -6275,6 +6277,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
62756277
{
62766278
if ((rhs_type->tt_type == VAR_FUNC
62776279
|| rhs_type->tt_type == VAR_PARTIAL)
6280+
&& !lhs.lhs_has_index
62786281
&& var_wrong_func_name(lhs.lhs_name, TRUE))
62796282
goto theend;
62806283

0 commit comments

Comments
 (0)