Patch 8.2.2742
Problem: Vim9: when compiling a function fails it is cleared.
Solution: Keep the function lines, prevent execution with a different
status. (closes #8093)
Files: src/vim9compile.c, src/structs.h, src/vim9execute.c,
src/testdir/test_vim9_func.vim
*** ../vim-8.2.2741/src/vim9compile.c 2021-04-09 22:12:41.293324192 +0200
--- src/vim9compile.c 2021-04-10 13:18:30.231728759 +0200
***************
*** 1791,1798 ****
{
switch (ufunc->uf_def_status)
{
! case UF_NOT_COMPILED: break;
! case UF_TO_BE_COMPILED: return TRUE;
case UF_COMPILED:
{
#ifdef FEAT_PROFILE
--- 1791,1799 ----
{
switch (ufunc->uf_def_status)
{
! case UF_TO_BE_COMPILED:
! return TRUE;
!
case UF_COMPILED:
{
#ifdef FEAT_PROFILE
***************
*** 1805,1811 ****
break;
#endif
}
! case UF_COMPILING: break;
}
return FALSE;
}
--- 1806,1816 ----
break;
#endif
}
!
! case UF_NOT_COMPILED:
! case UF_COMPILE_ERROR:
! case UF_COMPILING:
! break;
}
return FALSE;
}
***************
*** 1834,1840 ****
return FAIL;
}
! if (ufunc->uf_def_status != UF_NOT_COMPILED)
{
int i;
--- 1839,1846 ----
return FAIL;
}
! if (ufunc->uf_def_status != UF_NOT_COMPILED
! && ufunc->uf_def_status != UF_COMPILE_ERROR)
{
int i;
***************
*** 9007,9020 ****
--def_functions.ga_len;
ufunc->uf_dfunc_idx = 0;
}
! ufunc->uf_def_status = UF_NOT_COMPILED;
while (cctx.ctx_scope != NULL)
drop_scope(&cctx);
- // Don't execute this function body.
- ga_clear_strings(&ufunc->uf_lines);
-
if (errormsg != NULL)
emsg(errormsg);
else if (did_emsg == did_emsg_before)
--- 9013,9023 ----
--def_functions.ga_len;
ufunc->uf_dfunc_idx = 0;
}
! ufunc->uf_def_status = UF_COMPILE_ERROR;
while (cctx.ctx_scope != NULL)
drop_scope(&cctx);
if (errormsg != NULL)
emsg(errormsg);
else if (did_emsg == did_emsg_before)
*** ../vim-8.2.2741/src/structs.h 2021-04-05 22:27:33.402532604 +0200
--- src/structs.h 2021-04-10 13:11:00.725143949 +0200
***************
*** 1583,1592 ****
// values used for "uf_def_status"
typedef enum {
! UF_NOT_COMPILED,
! UF_TO_BE_COMPILED,
! UF_COMPILING,
! UF_COMPILED
} def_status_T;
/*
--- 1583,1593 ----
// values used for "uf_def_status"
typedef enum {
! UF_NOT_COMPILED, // executed with interpreter
! UF_TO_BE_COMPILED, // to be compiled before execution
! UF_COMPILING, // in compile_def_function()
! UF_COMPILED, // successfully compiled
! UF_COMPILE_ERROR // compilation error, cannot execute
} def_status_T;
/*
*** ../vim-8.2.2741/src/vim9execute.c 2021-04-09 20:22:57.843301002 +0200
--- src/vim9execute.c 2021-04-10 13:13:22.108713760 +0200
***************
*** 1297,1302 ****
--- 1297,1303 ----
#define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) +
ectx.ec_frame_idx + STACK_FRAME_SIZE + idx)
if (ufunc->uf_def_status == UF_NOT_COMPILED
+ || ufunc->uf_def_status == UF_COMPILE_ERROR
|| (func_needs_compiling(ufunc, PROFILING(ufunc))
&& compile_def_function(ufunc, FALSE, PROFILING(ufunc), NULL)
== FAIL))
*** ../vim-8.2.2741/src/testdir/test_vim9_func.vim 2021-04-09
22:12:41.297324181 +0200
--- src/testdir/test_vim9_func.vim 2021-04-10 13:31:24.377460382 +0200
***************
*** 1498,1504 ****
so Xdef
delete('Xdef')
! g:Func0()->assert_equal(0)
g:Func1()->assert_equal('Func1')
g:Func2()->assert_equal('Func2')
--- 1498,1504 ----
so Xdef
delete('Xdef')
! assert_fails('g:Func0()', 'E1091:')
g:Func1()->assert_equal('Func1')
g:Func2()->assert_equal('Func2')
***************
*** 2591,2596 ****
--- 2591,2610 ----
CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:')
enddef
+ def Test_compile_error()
+ var lines =<< trim END
+ def g:Broken()
+ echo 'a' + {}
+ enddef
+ call g:Broken()
+ END
+ # First call: compilation error
+ CheckScriptFailure(lines, 'E1051: Wrong argument type for +')
+
+ # Second call won't try compiling again
+ assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
+ enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.2741/src/version.c 2021-04-09 22:12:41.297324181 +0200
--- src/version.c 2021-04-10 13:28:57.881877822 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2742,
/**/
--
>From "know your smileys":
|-P Reaction to unusually ugly C code
/// 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/202104101143.13ABh1Wr174847%40masaka.moolenaar.net.