changeset 28156:088d8dc22045 v8.2.4602

patch 8.2.4602: Vim9: not enough test coverage for executing :def function Commit: https://github.com/vim/vim/commit/397a87ac1c9857eb0d5ec3add69e3b9ab6b0c77c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 20 21:14:15 2022 +0000 patch 8.2.4602: Vim9: not enough test coverage for executing :def function Problem: Vim9: not enough test coverage for executing :def function. Solution: Add a few more tests. Fix uncovered problem. Remove dead code.
author Bram Moolenaar <Bram@vim.org>
date Sun, 20 Mar 2022 22:15:02 +0100
parents 42ba8af8a1dd
children 81034dff92a4
files src/proto/vim9instr.pro src/testdir/test_vim9_expr.vim src/testdir/test_vim9_script.vim src/version.c src/vim9.h src/vim9compile.c src/vim9execute.c src/vim9instr.c
diffstat 8 files changed, 82 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/proto/vim9instr.pro
+++ b/src/proto/vim9instr.pro
@@ -19,8 +19,8 @@ int generate_PUSHBOOL(cctx_T *cctx, varn
 int generate_PUSHSPEC(cctx_T *cctx, varnumber_T number);
 int generate_PUSHF(cctx_T *cctx, float_T fnumber);
 int generate_PUSHS(cctx_T *cctx, char_u **str);
-int generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel);
-int generate_PUSHJOB(cctx_T *cctx, job_T *job);
+int generate_PUSHCHANNEL(cctx_T *cctx);
+int generate_PUSHJOB(cctx_T *cctx);
 int generate_PUSHBLOB(cctx_T *cctx, blob_T *blob);
 int generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type);
 int generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type);
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -3312,6 +3312,29 @@ def Test_expr8_call_global()
   v9.CheckDefAndScriptFailure(lines, 'E117: Unknown function: ExistingGlobal')
 enddef
 
+def Test_expr8_autoload_var()
+  var auto_lines =<< trim END
+      let autofile#var = 'found'
+  END
+  mkdir('Xruntime/autoload', 'p')
+  writefile(auto_lines, 'Xruntime/autoload/autofile.vim')
+  var save_rtp = &rtp
+  &rtp = getcwd() .. '/Xruntime,' .. &rtp
+
+  var lines =<< trim END
+      assert_equal('found', autofile#var)
+  END
+  v9.CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+      echo autofile#other
+  END
+  v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: autofile#other')
+
+  &rtp = save_rtp
+  delete('Xruntime', 'rf')
+enddef
+
 def Test_expr8_call_autoload()
   var auto_lines =<< trim END
       def g:some#func(): string
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1246,6 +1246,37 @@ def Test_cexpr_vimscript()
       assert_equal(19, getqflist()[0].lnum)
   END
   v9.CheckScriptSuccess(lines)
+
+  lines =<< trim END
+      vim9script
+      def CexprFail()
+        au QuickfixCmdPre * echo g:doesnotexist
+        cexpr 'File otherFile line 99'
+        g:didContinue = 'yes'
+      enddef
+      CexprFail()
+      g:didContinue = 'also'
+  END
+  g:didContinue = 'no'
+  v9.CheckScriptFailure(lines, 'E121: Undefined variable: g:doesnotexist')
+  assert_equal('no', g:didContinue)
+  au! QuickfixCmdPre
+
+  lines =<< trim END
+      vim9script
+      def CexprFail()
+        cexpr g:aNumber
+        g:didContinue = 'yes'
+      enddef
+      CexprFail()
+      g:didContinue = 'also'
+  END
+  g:aNumber = 123
+  g:didContinue = 'no'
+  v9.CheckScriptFailure(lines, 'E777: String or List expected')
+  assert_equal('no', g:didContinue)
+  unlet g:didContinue
+
   set errorformat&
 enddef
 
@@ -1813,6 +1844,10 @@ def Test_echo_cmd()
   echo str1 str2
   assert_match('^some more$', g:Screenline(&lines))
 
+  echo "one\ntwo"
+  assert_match('^one$', g:Screenline(&lines - 1))
+  assert_match('^two$', g:Screenline(&lines))
+
   v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:')
 enddef
 
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4602,
+/**/
     4601,
 /**/
     4600,
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -87,8 +87,8 @@ typedef enum {
     ISN_PUSHS,		// push string isn_arg.string
     ISN_PUSHBLOB,	// push blob isn_arg.blob
     ISN_PUSHFUNC,	// push func isn_arg.string
-    ISN_PUSHCHANNEL,	// push channel isn_arg.channel
-    ISN_PUSHJOB,	// push channel isn_arg.job
+    ISN_PUSHCHANNEL,	// push NULL channel
+    ISN_PUSHJOB,	// push NULL job
     ISN_NEWLIST,	// push list from stack items, size is isn_arg.number
     ISN_NEWDICT,	// push dict from stack items, size is isn_arg.number
     ISN_NEWPARTIAL,	// push NULL partial
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2238,10 +2238,10 @@ compile_assignment(char_u *arg, exarg_T 
 			generate_NEWDICT(cctx, 0);
 			break;
 		    case VAR_JOB:
-			generate_PUSHJOB(cctx, NULL);
+			generate_PUSHJOB(cctx);
 			break;
 		    case VAR_CHANNEL:
-			generate_PUSHCHANNEL(cctx, NULL);
+			generate_PUSHCHANNEL(cctx);
 			break;
 		    case VAR_NUMBER:
 		    case VAR_UNKNOWN:
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2611,8 +2611,10 @@ exec_instructions(ectx_T *ectx)
 
 	    case ISN_CEXPR_AUCMD:
 #ifdef FEAT_QUICKFIX
+		force_abort = TRUE;
 		if (trigger_cexpr_autocmd(iptr->isn_arg.number) == FAIL)
 		    goto on_error;
+		force_abort = FALSE;
 #endif
 		break;
 
@@ -3040,7 +3042,9 @@ exec_instructions(ectx_T *ectx)
 			s = tv2string(tv, &tofree, numbuf, 0);
 			if (s == NULL || *s == NUL)
 			{
+			    // cannot happen?
 			    clear_tv(tv);
+			    vim_free(tofree);
 			    goto on_error;
 			}
 		    }
@@ -3270,17 +3274,13 @@ exec_instructions(ectx_T *ectx)
 		    case ISN_PUSHCHANNEL:
 #ifdef FEAT_JOB_CHANNEL
 			tv->v_type = VAR_CHANNEL;
-			tv->vval.v_channel = iptr->isn_arg.channel;
-			if (tv->vval.v_channel != NULL)
-			    ++tv->vval.v_channel->ch_refcount;
+			tv->vval.v_channel = NULL;
 #endif
 			break;
 		    case ISN_PUSHJOB:
 #ifdef FEAT_JOB_CHANNEL
 			tv->v_type = VAR_JOB;
-			tv->vval.v_job = iptr->isn_arg.job;
-			if (tv->vval.v_job != NULL)
-			    ++tv->vval.v_job->jv_refcount;
+			tv->vval.v_job = NULL;
 #endif
 			break;
 		    default:
@@ -5644,26 +5644,12 @@ list_instructions(char *pfx, isn_T *inst
 		break;
 	    case ISN_PUSHCHANNEL:
 #ifdef FEAT_JOB_CHANNEL
-		{
-		    channel_T *channel = iptr->isn_arg.channel;
-
-		    smsg("%s%4d PUSHCHANNEL %d", pfx, current,
-					 channel == NULL ? 0 : channel->ch_id);
-		}
+		smsg("%s%4d PUSHCHANNEL 0", pfx, current);
 #endif
 		break;
 	    case ISN_PUSHJOB:
 #ifdef FEAT_JOB_CHANNEL
-		{
-		    typval_T	tv;
-		    char_u	*name;
-		    char_u	buf[NUMBUFLEN];
-
-		    tv.v_type = VAR_JOB;
-		    tv.vval.v_job = iptr->isn_arg.job;
-		    name = job_to_string_buf(&tv, buf);
-		    smsg("%s%4d PUSHJOB \"%s\"", pfx, current, name);
-		}
+		smsg("%s%4d PUSHJOB \"no process\"", pfx, current);
 #endif
 		break;
 	    case ISN_PUSHEXC:
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -592,12 +592,12 @@ generate_tv_PUSH(cctx_T *cctx, typval_T 
 	    case VAR_JOB:
 		if (tv->vval.v_job != NULL)
 		    iemsg("non-null job constant not supported");
-		generate_PUSHJOB(cctx, NULL);
+		generate_PUSHJOB(cctx);
 		break;
 	    case VAR_CHANNEL:
 		if (tv->vval.v_channel != NULL)
 		    iemsg("non-null channel constant not supported");
-		generate_PUSHCHANNEL(cctx, NULL);
+		generate_PUSHCHANNEL(cctx);
 		break;
 #endif
 	    case VAR_FUNC:
@@ -723,36 +723,30 @@ generate_PUSHS(cctx_T *cctx, char_u **st
 }
 
 /*
- * Generate an ISN_PUSHCHANNEL instruction.
- * Consumes "channel".
+ * Generate an ISN_PUSHCHANNEL instruction.  Channel is always NULL.
  */
     int
-generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel)
+generate_PUSHCHANNEL(cctx_T *cctx)
 {
     isn_T	*isn;
 
     RETURN_OK_IF_SKIP(cctx);
     if ((isn = generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel)) == NULL)
 	return FAIL;
-    isn->isn_arg.channel = channel;
-
     return OK;
 }
 
 /*
- * Generate an ISN_PUSHJOB instruction.
- * Consumes "job".
+ * Generate an ISN_PUSHJOB instruction.  Job is always NULL.
  */
     int
-generate_PUSHJOB(cctx_T *cctx, job_T *job)
+generate_PUSHJOB(cctx_T *cctx)
 {
     isn_T	*isn;
 
     RETURN_OK_IF_SKIP(cctx);
     if ((isn = generate_instr_type(cctx, ISN_PUSHJOB, &t_job)) == NULL)
 	return FAIL;
-    isn->isn_arg.job = job;
-
     return OK;
 }
 
@@ -2081,18 +2075,6 @@ delete_instr(isn_T *isn)
 	    blob_unref(isn->isn_arg.blob);
 	    break;
 
-	case ISN_PUSHJOB:
-#ifdef FEAT_JOB_CHANNEL
-	    job_unref(isn->isn_arg.job);
-#endif
-	    break;
-
-	case ISN_PUSHCHANNEL:
-#ifdef FEAT_JOB_CHANNEL
-	    channel_unref(isn->isn_arg.channel);
-#endif
-	    break;
-
 	case ISN_UCALL:
 	    vim_free(isn->isn_arg.ufunc.cuf_name);
 	    break;
@@ -2241,7 +2223,9 @@ delete_instr(isn_T *isn)
 	case ISN_PROF_END:
 	case ISN_PROF_START:
 	case ISN_PUSHBOOL:
+	case ISN_PUSHCHANNEL:
 	case ISN_PUSHF:
+	case ISN_PUSHJOB:
 	case ISN_PUSHNR:
 	case ISN_PUSHSPEC:
 	case ISN_PUT: