From: Bram Moolenaar Date: Sat, 23 Jan 2021 12:39:14 +0000 (+0100) Subject: patch 8.2.2395: Vim9: error for wrong type may report wrong line number X-Git-Tag: v8.2.2395 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a562c184d98d82bb7506caf2071cfe15a92fa43;p=vim 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) --- diff --git a/src/evalvars.c b/src/evalvars.c index dfc8e63f5..b6a6927d6 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -838,6 +838,8 @@ ex_let(exarg_T *eap) i = FAIL; if (has_assign || concat) { + int cur_lnum; + op[0] = '='; op[1] = NUL; if (*expr != '=') @@ -882,10 +884,15 @@ ex_let(exarg_T *eap) evalarg.eval_cookie = eap->cookie; } expr = skipwhite_and_linebreak(expr, &evalarg); + cur_lnum = SOURCING_LNUM; i = eval0(expr, &rettv, eap, &evalarg); if (eap->skip) --emsg_skip; clear_evalarg(&evalarg, eap); + + // Restore the line number so that any type error is given for the + // declaration, not the expression. + SOURCING_LNUM = cur_lnum; } if (eap->skip) { diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 992eeaa65..55beffa95 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -55,6 +55,8 @@ def Test_assignment_bool() CheckDefAndScriptFailure(['var x: bool = [1]'], 'E1012:') CheckDefAndScriptFailure(['var x: bool = {}'], 'E1012:') CheckDefAndScriptFailure(['var x: bool = "x"'], 'E1012:') + + CheckDefAndScriptFailure(['var x: bool = "x"', '', 'eval 0'], 'E1012:', 1) enddef def Test_syntax() diff --git a/src/version.c b/src/version.c index 63fc0b33b..7942e743f 100644 --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2395, /**/ 2394, /**/