Patch 8.2.3341

4 views
Skip to first unread message

Bram Moolenaar

unread,
Aug 14, 2021, 8:01:45 AM8/14/21
to vim...@googlegroups.com

Patch 8.2.3341
Problem: Vim9: function call aborted despite try/catch. (Naohiro Ono)
Solution: Ignore error caught by try/catch. (closes #8755)
Files: src/evalvars.c, src/vim9execute.c, src/message.c, src/time.c,
src/globals.h, src/testdir/vim9.vim, src/testdir/test_vim9_func.vim


*** ../vim-8.2.3340/src/evalvars.c 2021-08-05 20:39:59.350053671 +0200
--- src/evalvars.c 2021-08-14 13:16:16.665266352 +0200
***************
*** 1193,1199 ****
if (!VIM_ISWHITE(*arg) && !ends_excmd(*arg))
{
emsg_severe = TRUE;
! semsg(_(e_trailing_arg), arg);
break;
}
}
--- 1193,1200 ----
if (!VIM_ISWHITE(*arg) && !ends_excmd(*arg))
{
emsg_severe = TRUE;
! if (!error)
! semsg(_(e_trailing_arg), arg);
break;
}
}
*** ../vim-8.2.3340/src/vim9execute.c 2021-08-13 19:40:47.413028293 +0200
--- src/vim9execute.c 2021-08-14 13:40:32.889166319 +0200
***************
*** 844,855 ****
}

/*
! * Return TRUE if an error was given or CTRL-C was pressed.
*/
static int
! vim9_aborting(int prev_called_emsg)
{
! return called_emsg > prev_called_emsg || got_int || did_throw;
}

/*
--- 844,856 ----
}

/*
! * Return TRUE if an error was given (not caught in try/catch) or CTRL-C was
! * pressed.
*/
static int
! vim9_aborting(int prev_uncaught_emsg)
{
! return uncaught_emsg > prev_uncaught_emsg || got_int || did_throw;
}

/*
***************
*** 882,893 ****

if (ufunc == NULL)
{
! int called_emsg_before = called_emsg;

if (script_autoload(name, TRUE))
// loaded a package, search for the function again
ufunc = find_func(name, FALSE, NULL);
! if (vim9_aborting(called_emsg_before))
return FAIL; // bail out if loading the script caused an error
}

--- 883,895 ----

if (ufunc == NULL)
{
! int prev_uncaught_emsg = uncaught_emsg;

if (script_autoload(name, TRUE))
// loaded a package, search for the function again
ufunc = find_func(name, FALSE, NULL);
!
! if (vim9_aborting(prev_uncaught_emsg))
return FAIL; // bail out if loading the script caused an error
}

*** ../vim-8.2.3340/src/message.c 2021-08-09 19:59:01.442811242 +0200
--- src/message.c 2021-08-14 13:36:45.905865952 +0200
***************
*** 733,739 ****
flush_buffers(FLUSH_MINIMAL); // flush internal buffers
++did_emsg; // flag for DoOneCmd()
#ifdef FEAT_EVAL
! did_uncaught_emsg = TRUE;
#endif
}

--- 733,739 ----
flush_buffers(FLUSH_MINIMAL); // flush internal buffers
++did_emsg; // flag for DoOneCmd()
#ifdef FEAT_EVAL
! ++uncaught_emsg;
#endif
}

*** ../vim-8.2.3340/src/time.c 2021-07-27 22:00:39.753712380 +0200
--- src/time.c 2021-08-14 13:38:00.969628229 +0200
***************
*** 520,525 ****
--- 520,526 ----
int save_timer_busy = timer_busy;
int save_vgetc_busy = vgetc_busy;
int save_did_emsg = did_emsg;
+ int prev_uncaught_emsg = uncaught_emsg;
int save_called_emsg = called_emsg;
int save_must_redraw = must_redraw;
int save_trylevel = trylevel;
***************
*** 536,542 ****
vgetc_busy = 0;
called_emsg = 0;
did_emsg = FALSE;
- did_uncaught_emsg = FALSE;
must_redraw = 0;
trylevel = 0;
did_throw = FALSE;
--- 537,542 ----
***************
*** 555,561 ****
did_one = TRUE;
timer_busy = save_timer_busy;
vgetc_busy = save_vgetc_busy;
! if (did_uncaught_emsg)
++timer->tr_emsg_count;
did_emsg = save_did_emsg;
called_emsg = save_called_emsg;
--- 555,561 ----
did_one = TRUE;
timer_busy = save_timer_busy;
vgetc_busy = save_vgetc_busy;
! if (uncaught_emsg > prev_uncaught_emsg)
++timer->tr_emsg_count;
did_emsg = save_did_emsg;
called_emsg = save_called_emsg;
*** ../vim-8.2.3340/src/globals.h 2021-08-13 19:40:47.417028286 +0200
--- src/globals.h 2021-08-14 13:38:39.769507984 +0200
***************
*** 238,245 ****
EXTERN int did_emsg_cumul; // cumulative did_emsg, increased
// when did_emsg is reset.
EXTERN int called_vim_beep; // set if vim_beep() is called
! EXTERN int did_uncaught_emsg; // emsg() was called and did not
! // cause an exception
#endif
EXTERN int did_emsg_syntax; // did_emsg set because of a
// syntax error
--- 238,245 ----
EXTERN int did_emsg_cumul; // cumulative did_emsg, increased
// when did_emsg is reset.
EXTERN int called_vim_beep; // set if vim_beep() is called
! EXTERN int uncaught_emsg; // number of times emsg() was
! // called and did show a message
#endif
EXTERN int did_emsg_syntax; // did_emsg set because of a
// syntax error
*** ../vim-8.2.3340/src/testdir/vim9.vim 2021-08-12 19:27:46.458459623 +0200
--- src/testdir/vim9.vim 2021-08-14 13:52:46.695139514 +0200
***************
*** 12,21 ****
try
exe 'so ' .. fname
call Func()
- delfunc! Func
finally
call chdir(cwd)
call delete(fname)
endtry
endfunc

--- 12,21 ----
try
exe 'so ' .. fname
call Func()
finally
call chdir(cwd)
call delete(fname)
+ delfunc! Func
endtry
endfunc

*** ../vim-8.2.3340/src/testdir/test_vim9_func.vim 2021-08-10 22:51:59.369449616 +0200
--- src/testdir/test_vim9_func.vim 2021-08-14 13:56:17.906587355 +0200
***************
*** 160,165 ****
--- 160,211 ----
delete(dir, 'rf')
enddef

+ def Test_autoload_error_in_script()
+ var dir = 'Xdir/autoload'
+ mkdir(dir, 'p')
+
+ var lines =<< trim END
+ func scripterror#function()
+ let g:called_function = 'yes'
+ endfunc
+ let 0 = 1
+ END
+ writefile(lines, dir .. '/scripterror.vim')
+
+ var save_rtp = &rtp
+ exe 'set rtp=' .. getcwd() .. '/Xdir'
+
+ g:called_function = 'no'
+ # The error in the autoload script cannot be checked with assert_fails(), use
+ # CheckDefSuccess() instead of CheckDefFailure()
+ try
+ CheckDefSuccess(['scripterror#function()'])
+ catch
+ assert_match('E121: Undefined variable: 0', v:exception)
+ endtry
+ assert_equal('no', g:called_function)
+
+ lines =<< trim END
+ func scriptcaught#function()
+ let g:called_function = 'yes'
+ endfunc
+ try
+ let 0 = 1
+ catch
+ let g:caught = v:exception
+ endtry
+ END
+ writefile(lines, dir .. '/scriptcaught.vim')
+
+ g:called_function = 'no'
+ CheckDefSuccess(['scriptcaught#function()'])
+ assert_match('E121: Undefined variable: 0', g:caught)
+ assert_equal('yes', g:called_function)
+
+ &rtp = save_rtp
+ delete(dir, 'rf')
+ enddef
+
def CallRecursive(n: number): number
return CallRecursive(n + 1)
enddef
*** ../vim-8.2.3340/src/version.c 2021-08-13 20:12:08.344119978 +0200
--- src/version.c 2021-08-14 14:00:04.926000899 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3341,
/**/

--
The Law of VIM:
For each member b of the possible behaviour space B of program P, there exists
a finite time t before which at least one user u in the total user space U of
program P will request b becomes a member of the allowed behaviour space B'
(B' <= B).
In other words: Sooner or later everyone wants everything as an option.
-- Vince Negri

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages