]> granicus.if.org Git - vim/commitdiff
patch 8.2.3707: Vim9: constant expression of elseif not recognized v8.2.3707
authorBram Moolenaar <Bram@vim.org>
Tue, 30 Nov 2021 20:57:38 +0000 (20:57 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 30 Nov 2021 20:57:38 +0000 (20:57 +0000)
Problem:    Vim9: constant expression of elseif not recognized.
Solution:   Set instruction count before generating the expression.

src/testdir/test_vim9_disassemble.vim
src/version.c
src/vim9compile.c

index ba2d0a16ece045bf3e0f03aaa2495584f9526ca0..c90f54c9363233b9f95185fb12708569f346d256 100644 (file)
@@ -2296,6 +2296,38 @@ def Test_debugged()
         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
index 601055a0e5b7c5649494f382ed5183faa1b9fac9..e29cb3138d7ee953513d11562abd43fd3609d859 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3707,
 /**/
     3706,
 /**/
index 58149ed5c6f267a48cb4f6395b132d30b8d0bc7b..57bbb2b3c7cb4ac1906dfb4e63b5d70cd272a56e 100644 (file)
@@ -7785,7 +7785,7 @@ compile_elseif(char_u *arg, cctx_T *cctx)
 {
     char_u     *p = arg;
     garray_T   *instr = &cctx->ctx_instr;
-    int                instr_count = instr->ga_len;
+    int                instr_count;
     isn_T      *isn;
     scope_T    *scope = cctx->ctx_scope;
     ppconst_T  ppconst;
@@ -7871,19 +7871,15 @@ compile_elseif(char_u *arg, cctx_T *cctx)
        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;
-       }
     }
+
+    instr_count = instr->ga_len;
     if (compile_expr1(&p, cctx, &ppconst) == FAIL)
     {
        clear_ppconst(&ppconst);