Patch 8.2.1446
Problem:    Vim9: line number in error message is not correct.
Solution:   Set SOURCING_LNUM before calling emsg(). (closes #6708)
Files:      src/vim9execute.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.1445/src/vim9execute.c   2020-08-13 22:47:20.377992734 +0200
--- src/vim9execute.c   2020-08-14 18:33:49.009863442 +0200
***************
*** 1027,1032 ****
--- 1027,1033 ----
                        tv = STACK_TV_BOT(idx - count);
                        if (tv->v_type == VAR_CHANNEL || tv->v_type == VAR_JOB)
                        {
+                           SOURCING_LNUM = iptr->isn_lnum;
                            emsg(_(e_inval_string));
                            break;
                        }
***************
*** 1121,1126 ****
--- 1122,1128 ----
  
                    if (di == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_(e_undefvar), name);
                        goto on_error;
                    }
***************
*** 1169,1174 ****
--- 1171,1177 ----
  
                    if (di == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_("E121: Undefined variable: %c:%s"),
                                             namespace, iptr->isn_arg.string);
                        goto on_error;
***************
*** 1326,1331 ****
--- 1329,1335 ----
                    clear_tv(tv);
                    if (msg != NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(msg));
                        goto on_error;
                    }
***************
*** 1421,1426 ****
--- 1425,1431 ----
                        lidx = list->lv_len + lidx;
                    if (lidx < 0 || lidx > list->lv_len)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_(e_listidx), lidx);
                        goto on_error;
                    }
***************
*** 1457,1462 ****
--- 1462,1468 ----
  
                    if (dict == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_dictionary_not_set));
                        goto on_error;
                    }
***************
*** 1586,1591 ****
--- 1592,1598 ----
                        item = dict_find(dict, tv->vval.v_string, -1);
                        if (item != NULL)
                        {
+                           SOURCING_LNUM = iptr->isn_lnum;
                            semsg(_(e_duplicate_key), tv->vval.v_string);
                            dict_unref(dict);
                            goto on_error;
***************
*** 1749,1754 ****
--- 1756,1762 ----
                        if (tv->v_type == VAR_PARTIAL)
                        {
                            // TODO: use a garray_T on ectx.
+                           SOURCING_LNUM = iptr->isn_lnum;
                            emsg("Multiple closures not supported yet");
                            goto failed;
                        }
***************
*** 1852,1857 ****
--- 1860,1866 ----
            case ISN_PUSHEXC:
                if (current_exception == NULL)
                {
+                   SOURCING_LNUM = iptr->isn_lnum;
                    iemsg("Evaluating catch while current_exception is NULL");
                    goto failed;
                }
***************
*** 2175,2181 ****
                            case EXPR_DIV:  f1 = f1 / f2; break;
                            case EXPR_SUB:  f1 = f1 - f2; break;
                            case EXPR_ADD:  f1 = f1 + f2; break;
!                           default: emsg(_(e_modulus));
                                     goto on_error;
                        }
                        clear_tv(tv1);
--- 2184,2191 ----
                            case EXPR_DIV:  f1 = f1 / f2; break;
                            case EXPR_SUB:  f1 = f1 - f2; break;
                            case EXPR_ADD:  f1 = f1 + f2; break;
!                           default: SOURCING_LNUM = iptr->isn_lnum;
!                                    emsg(_(e_modulus));
                                     goto on_error;
                        }
                        clear_tv(tv1);
***************
*** 2228,2233 ****
--- 2238,2244 ----
                    tv = STACK_TV_BOT(-2);
                    if (tv->v_type != VAR_STRING)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_stringreq));
                        goto on_error;
                    }
***************
*** 2236,2241 ****
--- 2247,2253 ----
                    tv = STACK_TV_BOT(-1);
                    if (tv->v_type != VAR_NUMBER)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_number_exp));
                        goto on_error;
                    }
***************
*** 2266,2271 ****
--- 2278,2284 ----
                    tv = STACK_TV_BOT(-2);
                    if (tv->v_type != VAR_LIST)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_listreq));
                        goto on_error;
                    }
***************
*** 2274,2279 ****
--- 2287,2293 ----
                    tv = STACK_TV_BOT(-1);
                    if (tv->v_type != VAR_NUMBER)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_number_exp));
                        goto on_error;
                    }
***************
*** 2281,2286 ****
--- 2295,2301 ----
                    clear_tv(tv);
                    if ((li = list_find(list, n)) == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_(e_listidx), n);
                        goto on_error;
                    }
***************
*** 2354,2359 ****
--- 2369,2375 ----
  
                    if ((di = dict_find(dict, key, -1)) == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_(e_dictkey), key);
                        goto on_error;
                    }
***************
*** 2378,2383 ****
--- 2394,2400 ----
                    tv = STACK_TV_BOT(-1);
                    if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_dictreq));
                        goto on_error;
                    }
***************
*** 2386,2391 ****
--- 2403,2409 ----
                    if ((di = dict_find(dict, iptr->isn_arg.string, -1))
                                                                       == NULL)
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_(e_dictkey), iptr->isn_arg.string);
                        goto on_error;
                    }
***************
*** 2405,2410 ****
--- 2423,2429 ----
  #endif
                        )
                {
+                   SOURCING_LNUM = iptr->isn_lnum;
                    emsg(_(e_number_exp));
                    goto on_error;
                }
***************
*** 2441,2446 ****
--- 2460,2466 ----
                                || (tv->v_type == VAR_FUNC
                                               && ct->ct_type == VAR_PARTIAL)))
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_("E1029: Expected %s but got %s"),
                                    vartype_name(ct->ct_type),
                                    vartype_name(tv->v_type));
***************
*** 2461,2466 ****
--- 2481,2487 ----
                            || (list->lv_len > min_len
                                        && !iptr->isn_arg.checklen.cl_more_OK))
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        semsg(_("E1093: Expected %d items but got %d"),
                                     min_len, list == NULL ? 0 : list->lv_len);
                        goto on_error;
*** ../vim-8.2.1445/src/testdir/test_vim9_func.vim      2020-08-12 
17:35:55.655082129 +0200
--- src/testdir/test_vim9_func.vim      2020-08-14 18:31:23.078734049 +0200
***************
*** 1045,1050 ****
--- 1045,1051 ----
    call writefile(lines, 'Xdef')
    try
      source Xdef
+     assert_report('should have failed')
    catch /E476:/
      assert_match('Invalid command: invalid', v:exception)
      assert_match(', line 3$', v:throwpoint)
***************
*** 1064,1074 ****
--- 1065,1094 ----
    call writefile(lines, 'Xdef')
    try
      source Xdef
+     assert_report('should have failed')
    catch /E476:/
      assert_match('Invalid command: invalid', v:exception)
      assert_match(', line 4$', v:throwpoint)
    endtry
  
+   lines =<< trim END
+     vim9script
+     def Func()
+       let db = #{foo: 1, bar: 2}
+       # comment
+       let x = db.asdf
+     enddef
+     defcompile
+     Func()
+   END
+   call writefile(lines, 'Xdef')
+   try
+     source Xdef
+     assert_report('should have failed')
+   catch /E716:/
+     assert_match('_Func, line 3$', v:throwpoint)
+   endtry
+ 
    call delete('Xdef')
  enddef
  
*** ../vim-8.2.1445/src/version.c       2020-08-14 17:08:12.012859486 +0200
--- src/version.c       2020-08-14 18:34:12.281721058 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1446,
  /**/

-- 
Some of the well known MS-Windows errors:
        ETIME           Wrong time, wait a little while
        ECRASH          Try again...
        EDETECT         Unable to detect errors
        EOVER           You lost!  Play another game?
        ENOCLUE         Eh, what did you want?

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202008141635.07EGZoBC091991%40masaka.moolenaar.net.

Raspunde prin e-mail lui