Patch 8.2.4602
Problem:    Vim9: not enough test coverage for executing :def function.
Solution:   Add a few more tests.  Fix uncovered problem.  Remove dead code.
Files:      src/vim9execute.c, src/vim9.h, src/vim9instr.c,
            src/proto/vim9instr.pro, src/vim9compile.c,
            src/testdir/test_vim9_script.vim, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.4601/src/vim9execute.c   2022-03-20 17:46:01.797053490 +0000
--- src/vim9execute.c   2022-03-20 21:11:25.170584849 +0000
***************
*** 2611,2618 ****
--- 2611,2620 ----
  
            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,3046 ****
--- 3042,3050 ----
                        s = tv2string(tv, &tofree, numbuf, 0);
                        if (s == NULL || *s == NUL)
                        {
+                           // cannot happen?
                            clear_tv(tv);
+                           vim_free(tofree);
                            goto on_error;
                        }
                    }
***************
*** 3270,3286 ****
                    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;
  #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;
  #endif
                        break;
                    default:
--- 3274,3286 ----
                    case ISN_PUSHCHANNEL:
  #ifdef FEAT_JOB_CHANNEL
                        tv->v_type = VAR_CHANNEL;
!                       tv->vval.v_channel = NULL;
  #endif
                        break;
                    case ISN_PUSHJOB:
  #ifdef FEAT_JOB_CHANNEL
                        tv->v_type = VAR_JOB;
!                       tv->vval.v_job = NULL;
  #endif
                        break;
                    default:
***************
*** 5644,5669 ****
                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);
!               }
  #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);
!               }
  #endif
                break;
            case ISN_PUSHEXC:
--- 5644,5655 ----
                break;
            case ISN_PUSHCHANNEL:
  #ifdef FEAT_JOB_CHANNEL
!               smsg("%s%4d PUSHCHANNEL 0", pfx, current);
  #endif
                break;
            case ISN_PUSHJOB:
  #ifdef FEAT_JOB_CHANNEL
!               smsg("%s%4d PUSHJOB \"no process\"", pfx, current);
  #endif
                break;
            case ISN_PUSHEXC:
*** ../vim-8.2.4601/src/vim9.h  2022-03-15 19:29:26.546954678 +0000
--- src/vim9.h  2022-03-20 21:06:24.051429436 +0000
***************
*** 87,94 ****
      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_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
--- 87,94 ----
      ISN_PUSHS,                // push string isn_arg.string
      ISN_PUSHBLOB,     // push blob isn_arg.blob
      ISN_PUSHFUNC,     // push func isn_arg.string
!     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
*** ../vim-8.2.4601/src/vim9instr.c     2022-03-15 20:21:26.397378123 +0000
--- src/vim9instr.c     2022-03-20 21:12:33.302399688 +0000
***************
*** 592,603 ****
            case VAR_JOB:
                if (tv->vval.v_job != NULL)
                    iemsg("non-null job constant not supported");
!               generate_PUSHJOB(cctx, NULL);
                break;
            case VAR_CHANNEL:
                if (tv->vval.v_channel != NULL)
                    iemsg("non-null channel constant not supported");
!               generate_PUSHCHANNEL(cctx, NULL);
                break;
  #endif
            case VAR_FUNC:
--- 592,603 ----
            case VAR_JOB:
                if (tv->vval.v_job != NULL)
                    iemsg("non-null job constant not supported");
!               generate_PUSHJOB(cctx);
                break;
            case VAR_CHANNEL:
                if (tv->vval.v_channel != NULL)
                    iemsg("non-null channel constant not supported");
!               generate_PUSHCHANNEL(cctx);
                break;
  #endif
            case VAR_FUNC:
***************
*** 723,758 ****
  }
  
  /*
!  * Generate an ISN_PUSHCHANNEL instruction.
!  * Consumes "channel".
   */
      int
! generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel)
  {
      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".
   */
      int
! generate_PUSHJOB(cctx_T *cctx, job_T *job)
  {
      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;
  }
  
--- 723,752 ----
  }
  
  /*
!  * Generate an ISN_PUSHCHANNEL instruction.  Channel is always NULL.
   */
      int
! 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;
      return OK;
  }
  
  /*
!  * Generate an ISN_PUSHJOB instruction.  Job is always NULL.
   */
      int
! 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;
      return OK;
  }
  
***************
*** 2081,2098 ****
            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;
--- 2075,2080 ----
***************
*** 2241,2247 ****
--- 2223,2231 ----
        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:
*** ../vim-8.2.4601/src/proto/vim9instr.pro     2022-01-25 15:51:52.430855187 
+0000
--- src/proto/vim9instr.pro     2022-03-20 21:12:12.482456091 +0000
***************
*** 19,26 ****
  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_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);
--- 19,26 ----
  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);
! 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);
*** ../vim-8.2.4601/src/vim9compile.c   2022-03-18 21:41:43.816964266 +0000
--- src/vim9compile.c   2022-03-20 21:12:20.742433693 +0000
***************
*** 2238,2247 ****
                        generate_NEWDICT(cctx, 0);
                        break;
                    case VAR_JOB:
!                       generate_PUSHJOB(cctx, NULL);
                        break;
                    case VAR_CHANNEL:
!                       generate_PUSHCHANNEL(cctx, NULL);
                        break;
                    case VAR_NUMBER:
                    case VAR_UNKNOWN:
--- 2238,2247 ----
                        generate_NEWDICT(cctx, 0);
                        break;
                    case VAR_JOB:
!                       generate_PUSHJOB(cctx);
                        break;
                    case VAR_CHANNEL:
!                       generate_PUSHCHANNEL(cctx);
                        break;
                    case VAR_NUMBER:
                    case VAR_UNKNOWN:
*** ../vim-8.2.4601/src/testdir/test_vim9_script.vim    2022-03-20 
18:50:56.536291286 +0000
--- src/testdir/test_vim9_script.vim    2022-03-20 20:21:17.953766085 +0000
***************
*** 1246,1251 ****
--- 1246,1282 ----
        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,1818 ****
--- 1844,1853 ----
    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
  
*** ../vim-8.2.4601/src/testdir/test_vim9_expr.vim      2022-03-16 
17:56:30.379316935 +0000
--- src/testdir/test_vim9_expr.vim      2022-03-20 20:47:58.382270769 +0000
***************
*** 3312,3317 ****
--- 3312,3340 ----
    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
*** ../vim-8.2.4601/src/version.c       2022-03-20 18:50:56.540291277 +0000
--- src/version.c       2022-03-20 20:05:54.869818535 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4602,
  /**/

-- 
       "To whoever finds this note -
       I have been imprisoned by my father who wishes me to marry
       against my will.  Please please please please come and rescue me.
       I am in the tall tower of Swamp Castle."
   SIR LAUNCELOT's eyes light up with holy inspiration.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20220320211443.4F11E1C7837%40moolenaar.net.

Raspunde prin e-mail lui