]> granicus.if.org Git - vim/commitdiff
patch 8.2.2395: Vim9: error for wrong type may report wrong line number v8.2.2395
authorBram Moolenaar <Bram@vim.org>
Sat, 23 Jan 2021 12:39:14 +0000 (13:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 23 Jan 2021 12:39:14 +0000 (13:39 +0100)
Problem:    Vim9: error for wrong type may report wrong line number.
Solution:   Save and restore the line number when evaluating the expression.
            (closes #7727)

src/evalvars.c
src/testdir/test_vim9_assign.vim
src/version.c

index dfc8e63f5a7aac27802b933c48468d28a9e2fbdc..b6a6927d60f38184f53ad2374b14d9531816b17f 100644 (file)
@@ -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)
        {
index 992eeaa655c9c83b5923f23ebc1d2b7dc3b998f2..55beffa958442fda84a65da69b10e2774d550420 100644 (file)
@@ -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()
index 63fc0b33bc74d79943dd814efe5ee9efac38d79d..7942e743f2f28f1b0c898f0aa3e64f7daf9d49ad 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2395,
 /**/
     2394,
 /**/