Skip to content

Commit 9a562c1

Browse files
committed
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Problem: Vim9: error for wrong type may report wrong line number. Solution: Save and restore the line number when evaluating the expression. (closes #7727)
1 parent 9ae3705 commit 9a562c1

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/evalvars.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ ex_let(exarg_T *eap)
838838
i = FAIL;
839839
if (has_assign || concat)
840840
{
841+
int cur_lnum;
842+
841843
op[0] = '=';
842844
op[1] = NUL;
843845
if (*expr != '=')
@@ -882,10 +884,15 @@ ex_let(exarg_T *eap)
882884
evalarg.eval_cookie = eap->cookie;
883885
}
884886
expr = skipwhite_and_linebreak(expr, &evalarg);
887+
cur_lnum = SOURCING_LNUM;
885888
i = eval0(expr, &rettv, eap, &evalarg);
886889
if (eap->skip)
887890
--emsg_skip;
888891
clear_evalarg(&evalarg, eap);
892+
893+
// Restore the line number so that any type error is given for the
894+
// declaration, not the expression.
895+
SOURCING_LNUM = cur_lnum;
889896
}
890897
if (eap->skip)
891898
{

src/testdir/test_vim9_assign.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def Test_assignment_bool()
5555
CheckDefAndScriptFailure(['var x: bool = [1]'], 'E1012:')
5656
CheckDefAndScriptFailure(['var x: bool = {}'], 'E1012:')
5757
CheckDefAndScriptFailure(['var x: bool = "x"'], 'E1012:')
58+
59+
CheckDefAndScriptFailure(['var x: bool = "x"', '', 'eval 0'], 'E1012:', 1)
5860
enddef
5961

6062
def Test_syntax()

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+
2395,
753755
/**/
754756
2394,
755757
/**/

0 commit comments

Comments
 (0)