diff src/vim9execute.c @ 22633:6589dae9696c v8.2.1865

patch 8.2.1865: Vim9: add() does not check type of argument Commit: https://github.com/vim/vim/commit/1dcae59957301b6b19aef49af648715f911a1378 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Oct 19 19:02:42 2020 +0200 patch 8.2.1865: Vim9: add() does not check type of argument Problem: Vim9: add() does not check type of argument. Solution: Inline the add() call. (closes https://github.com/vim/vim/issues/7160)
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Oct 2020 19:15:04 +0200
parents 672ee41a6a3b
children 4d4042683371
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2095,6 +2095,7 @@ call_def_function(
 				       || *skipwhite(tv->vval.v_string) == NUL)
 		{
 		    vim_free(tv->vval.v_string);
+		    SOURCING_LNUM = iptr->isn_lnum;
 		    emsg(_(e_throw_with_empty_string));
 		    goto failed;
 		}
@@ -2282,6 +2283,7 @@ call_def_function(
 		    typval_T *tv1 = STACK_TV_BOT(-2);
 		    typval_T *tv2 = STACK_TV_BOT(-1);
 
+		    // add two lists or blobs
 		    if (iptr->isn_type == ISN_ADDLIST)
 			eval_addlist(tv1, tv2);
 		    else
@@ -2291,6 +2293,25 @@ call_def_function(
 		}
 		break;
 
+	    case ISN_LISTAPPEND:
+		{
+		    typval_T	*tv1 = STACK_TV_BOT(-2);
+		    typval_T	*tv2 = STACK_TV_BOT(-1);
+		    list_T	*l = tv1->vval.v_list;
+
+		    // add an item to a list
+		    if (l == NULL)
+		    {
+			SOURCING_LNUM = iptr->isn_lnum;
+			emsg(_(e_cannot_add_to_null_list));
+			goto on_error;
+		    }
+		    if (list_append_tv(l, tv2) == FAIL)
+			goto failed;
+		    --ectx.ec_stack.ga_len;
+		}
+		break;
+
 	    // Computation with two arguments of unknown type
 	    case ISN_OPANY:
 		{
@@ -3410,6 +3431,7 @@ ex_disassemble(exarg_T *eap)
 	    case ISN_CONCAT: smsg("%4d CONCAT", current); break;
 	    case ISN_STRINDEX: smsg("%4d STRINDEX", current); break;
 	    case ISN_STRSLICE: smsg("%4d STRSLICE", current); break;
+	    case ISN_LISTAPPEND: smsg("%4d LISTAPPEND", current); break;
 	    case ISN_LISTINDEX: smsg("%4d LISTINDEX", current); break;
 	    case ISN_LISTSLICE: smsg("%4d LISTSLICE", current); break;
 	    case ISN_ANYINDEX: smsg("%4d ANYINDEX", current); break;