diff src/ex_eval.c @ 20538:9f921ba86d05 v8.2.0823

patch 8.2.0823: Vim9: script reload test is disabled Commit: https://github.com/vim/vim/commit/25e0f5863e9010a75a1ff0d04e8f886403968755 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 25 22:36:50 2020 +0200 patch 8.2.0823: Vim9: script reload test is disabled Problem: Vim9: script reload test is disabled. Solution: Compile a function in the context of the script where it was defined. Set execution stack for compiled function. Add a test that an error is reported for the right file/function.
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 May 2020 22:45:03 +0200
parents c225be44692a
children 9064044fd4f6
line wrap: on
line diff
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -146,8 +146,8 @@ cause_errthrow(
     int		severe,
     int		*ignore)
 {
-    struct msglist *elem;
-    struct msglist **plist;
+    msglist_T	*elem;
+    msglist_T	**plist;
 
     /*
      * Do nothing when displaying the interrupt message or reporting an
@@ -251,7 +251,7 @@ cause_errthrow(
 	    while (*plist != NULL)
 		plist = &(*plist)->next;
 
-	    elem = ALLOC_ONE(struct msglist);
+	    elem = ALLOC_CLEAR_ONE(msglist_T);
 	    if (elem == NULL)
 	    {
 		suppress_errthrow = TRUE;
@@ -287,6 +287,11 @@ cause_errthrow(
 			else
 			    (*msg_list)->throw_msg = tmsg;
 		    }
+
+		    // Get the source name and lnum now, it may change before
+		    // reaching do_errthrow().
+		    elem->sfile = estack_sfile();
+		    elem->slnum = SOURCING_LNUM;
 		}
 	    }
 	}
@@ -298,15 +303,16 @@ cause_errthrow(
  * Free a "msg_list" and the messages it contains.
  */
     static void
-free_msglist(struct msglist *l)
+free_msglist(msglist_T *l)
 {
-    struct msglist  *messages, *next;
+    msglist_T  *messages, *next;
 
     messages = l;
     while (messages != NULL)
     {
 	next = messages->next;
 	vim_free(messages->msg);
+	vim_free(messages->sfile);
 	vim_free(messages);
 	messages = next;
     }
@@ -428,7 +434,7 @@ get_exception_string(
     if (type == ET_ERROR)
     {
 	*should_free = TRUE;
-	mesg = ((struct msglist *)value)->throw_msg;
+	mesg = ((msglist_T *)value)->throw_msg;
 	if (cmdname != NULL && *cmdname != NUL)
 	{
 	    cmdlen = (int)STRLEN(cmdname);
@@ -526,23 +532,34 @@ throw_exception(void *value, except_type
     if (type == ET_ERROR)
 	// Store the original message and prefix the exception value with
 	// "Vim:" or, if a command name is given, "Vim(cmdname):".
-	excp->messages = (struct msglist *)value;
+	excp->messages = (msglist_T *)value;
 
     excp->value = get_exception_string(value, type, cmdname, &should_free);
     if (excp->value == NULL && should_free)
 	goto nomem;
 
     excp->type = type;
-    excp->throw_name = estack_sfile();
-    if (excp->throw_name == NULL)
-	excp->throw_name = vim_strsave((char_u *)"");
-    if (excp->throw_name == NULL)
+    if (type == ET_ERROR && ((msglist_T *)value)->sfile != NULL)
+    {
+	msglist_T *entry = (msglist_T *)value;
+
+	excp->throw_name = entry->sfile;
+	entry->sfile = NULL;
+	excp->throw_lnum = entry->slnum;
+    }
+    else
     {
-	if (should_free)
-	    vim_free(excp->value);
-	goto nomem;
+	excp->throw_name = estack_sfile();
+	if (excp->throw_name == NULL)
+	    excp->throw_name = vim_strsave((char_u *)"");
+	if (excp->throw_name == NULL)
+	{
+	    if (should_free)
+		vim_free(excp->value);
+	    goto nomem;
+	}
+	excp->throw_lnum = SOURCING_LNUM;
     }
-    excp->throw_lnum = SOURCING_LNUM;
 
     if (p_verbose >= 13 || debug_break_level > 0)
     {