Patch 8.2.3707
Problem: Vim9: constant expression of elseif not recognized.
Solution: Set instruction count before generating the expression.
Files: src/vim9compile.c, src/testdir/test_vim9_disassemble.vim
*** ../vim-8.2.3706/src/vim9compile.c 2021-11-30 16:14:44.052582170 +0000
--- src/vim9compile.c 2021-11-30 20:44:47.462307244 +0000
***************
*** 7785,7791 ****
{
char_u *p = arg;
garray_T *instr = &cctx->ctx_instr;
! int instr_count = instr->ga_len;
isn_T *isn;
scope_T *scope = cctx->ctx_scope;
ppconst_T ppconst;
--- 7785,7791 ----
{
char_u *p = arg;
garray_T *instr = &cctx->ctx_instr;
! int instr_count;
isn_T *isn;
scope_T *scope = cctx->ctx_scope;
ppconst_T ppconst;
***************
*** 7871,7889 ****
cctx->ctx_skip = SKIP_UNKNOWN;
#ifdef FEAT_PROFILE
if (cctx->ctx_compile_type == CT_PROFILE)
- {
// the previous block was skipped, need to profile this line
generate_instr(cctx, ISN_PROF_START);
- instr_count = instr->ga_len;
- }
#endif
if (cctx->ctx_compile_type == CT_DEBUG)
- {
// the previous block was skipped, may want to debug this line
generate_instr_debug(cctx);
- instr_count = instr->ga_len;
- }
}
if (compile_expr1(&p, cctx, &ppconst) == FAIL)
{
clear_ppconst(&ppconst);
--- 7871,7885 ----
cctx->ctx_skip = SKIP_UNKNOWN;
#ifdef FEAT_PROFILE
if (cctx->ctx_compile_type == CT_PROFILE)
// the previous block was skipped, need to profile this line
generate_instr(cctx, ISN_PROF_START);
#endif
if (cctx->ctx_compile_type == CT_DEBUG)
// the previous block was skipped, may want to debug this line
generate_instr_debug(cctx);
}
+
+ instr_count = instr->ga_len;
if (compile_expr1(&p, cctx, &ppconst) == FAIL)
{
clear_ppconst(&ppconst);
*** ../vim-8.2.3706/src/testdir/test_vim9_disassemble.vim 2021-09-16 15:15:00.204224417 +0100
--- src/testdir/test_vim9_disassemble.vim 2021-11-30 20:44:12.798355993 +0000
***************
*** 2296,2301 ****
--- 2296,2333 ----
res)
enddef
+ def s:ElseifConstant()
+ if g:value
+ echo "one"
+ elseif true
+ echo "true"
+ elseif false
+ echo "false"
+ endif
+ enddef
+
+ def Test_debug_elseif_constant()
+ var res = execute('disass s:ElseifConstant')
+ assert_match('<SNR>\d*_ElseifConstant\_s*' ..
+ 'if g:value\_s*' ..
+ '0 LOADG g:value\_s*' ..
+ '1 COND2BOOL\_s*' ..
+ '2 JUMP_IF_FALSE -> 6\_s*' ..
+ 'echo "one"\_s*' ..
+ '3 PUSHS "one"\_s*' ..
+ '4 ECHO 1\_s*' ..
+ 'elseif true\_s*' ..
+ '5 JUMP -> 8\_s*' ..
+ 'echo "true"\_s*' ..
+ '6 PUSHS "true"\_s*' ..
+ '7 ECHO 1\_s*' ..
+ 'elseif false\_s*' ..
+ 'echo "false"\_s*' ..
+ 'endif\_s*' ..
+ '\d RETURN void*',
+ res)
+ enddef
+
def s:DebugElseif()
var b = false
if b
*** ../vim-8.2.3706/src/version.c 2021-11-30 20:21:25.657045218 +0000
--- src/version.c 2021-11-30 20:37:23.618970107 +0000
***************
*** 755,756 ****
--- 755,758 ----
{ /* Add new patch number below this line */
+ /**/
+ 3707,
/**/
--
If all you have is a hammer, everything looks like a nail.
When your hammer is C++, everything begins to look like a thumb.
-- Steve Hoflich, comp.lang.c++
/// 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 ///