]> granicus.if.org Git - vim/commitdiff
patch 8.2.0224: compiling :elseif not tested yet v8.2.0224
authorBram Moolenaar <Bram@vim.org>
Thu, 6 Feb 2020 19:39:45 +0000 (20:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 6 Feb 2020 19:39:45 +0000 (20:39 +0100)
Problem:    compiling :elseif not tested yet.
Solution:   Add test for :elseif.  Fix generating jumps.

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

index 3345758032e67a5d91a854947c9fbfb335ac57b3..b011342976229783ab817635bdb121ab88ab8019 100644 (file)
@@ -216,5 +216,67 @@ def Test_disassembleCall()
         \, res)
 enddef
 
+def HasEval()
+  if has("eval")
+    echo "yes"
+  else
+    echo "no"
+  endif
+enddef
+
+def HasNothing()
+  if has("nothing")
+    echo "yes"
+  else
+    echo "no"
+  endif
+enddef
+
+def HasSomething()
+  if has("nothing")
+    echo "nothing"
+  elseif has("something")
+    echo "something"
+  elseif has("eval")
+    echo "eval"
+  elseif has("less")
+    echo "less"
+  endif
+enddef
+
+def Test_compile_const_expr()
+  assert_equal("\nyes", execute('call HasEval()'))
+  let instr = execute('disassemble HasEval')
+  assert_match('HasEval.*'
+        \ .. 'if has("eval").*'
+        \ .. ' PUSHS "yes".*'
+        \, instr)
+  assert_notmatch('JUMP', instr)
+
+  assert_equal("\nno", execute('call HasNothing()'))
+  instr = execute('disassemble HasNothing')
+  assert_match('HasNothing.*'
+        \ .. 'if has("nothing").*'
+        \ .. 'else.*'
+        \ .. ' PUSHS "no".*'
+        \, instr)
+  assert_notmatch('PUSHS "yes"', instr)
+  assert_notmatch('JUMP', instr)
+
+  assert_equal("\neval", execute('call HasSomething()'))
+  instr = execute('disassemble HasSomething')
+  assert_match('HasSomething.*'
+        \ .. 'if has("nothing").*'
+        \ .. 'elseif has("something").*'
+        \ .. 'elseif has("eval").*'
+        \ .. ' PUSHS "eval".*'
+        \ .. 'elseif has("less").*'
+        \, instr)
+  assert_notmatch('PUSHS "nothing"', instr)
+  assert_notmatch('PUSHS "something"', instr)
+  assert_notmatch('PUSHS "less"', instr)
+  assert_notmatch('JUMP', instr)
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 4b57bde0bd2b6d6debdf9723bf14db43b4ddbca4..892806f39a622ef8b84ce27d39890f8e7238d7e3 100644 (file)
@@ -459,34 +459,22 @@ def do_something():
 EOF
 endfunc
 
-def HasEval()
-  if has('eval')
-    echo 'yes'
+def IfElse(what: number): string
+  let res = ''
+  if what == 1
+    res = "one"
+  elseif what == 2
+    res = "two"
   else
-    echo 'no'
-  endif
-enddef
-
-def HasNothing()
-  if has('nothing')
-    echo 'yes'
-  else
-    echo 'no'
+    res = "three"
   endif
+  return res
 enddef
 
-def Test_compile_const_expr()
-  assert_equal("\nyes", execute('call HasEval()'))
-  let instr = execute('disassemble HasEval')
-  assert_match('PUSHS "yes"', instr)
-  assert_notmatch('PUSHS "no"', instr)
-  assert_notmatch('JUMP', instr)
-
-  assert_equal("\nno", execute('call HasNothing()'))
-  instr = execute('disassemble HasNothing')
-  assert_notmatch('PUSHS "yes"', instr)
-  assert_match('PUSHS "no"', instr)
-  assert_notmatch('JUMP', instr)
+def Test_if_elseif_else()
+  assert_equal('one', IfElse(1))
+  assert_equal('two', IfElse(2))
+  assert_equal('three', IfElse(3))
 enddef
 
 
index e76bdea7732043907bc002fe9b5e05e978fba846..3cb8bc29fa8419941a0c9bc5c79ec0ab688f58cb 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    224,
 /**/
     223,
 /**/
index 922618b0a09a741cb2a66e05f5c05d702be5cc25..1c76c8adb2aca2614f29dc4d6d31a3e4db5bf637 100644 (file)
@@ -3891,7 +3891,7 @@ compile_elseif(char_u *arg, cctx_T *cctx)
     }
     cctx->ctx_locals.ga_len = scope->se_local_count;
 
-    if (cctx->ctx_skip != TRUE)
+    if (cctx->ctx_skip == MAYBE)
     {
        if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
                                                    JUMP_ALWAYS, cctx) == FAIL)
@@ -3947,13 +3947,14 @@ compile_else(char_u *arg, cctx_T *cctx)
            return NULL;
     }
 
-    if (cctx->ctx_skip != TRUE)
+    if (cctx->ctx_skip == MAYBE)
     {
        if (scope->se_u.se_if.is_if_label >= 0)
        {
            // previous "if" or "elseif" jumps here
            isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
            isn->isn_arg.jump.jump_where = instr->ga_len;
+           scope->se_u.se_if.is_if_label = -1;
        }
     }