Patch 8.2.1205
Problem:    Vim9: && and || work different when not compiled.
Solution:   Keep the value.
Files:      src/eval.c, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.1204/src/eval.c  2020-07-13 21:59:25.391482336 +0200
--- src/eval.c  2020-07-13 22:27:11.555099451 +0200
***************
*** 2196,2201 ****
--- 2196,2202 ----
        long        result = FALSE;
        typval_T    var2;
        int         error;
+       int         vim9script = in_vim9script();
  
        if (evalarg == NULL)
        {
***************
*** 2206,2217 ****
        evaluate = orig_flags & EVAL_EVALUATE;
        if (evaluate)
        {
!           error = FALSE;
!           if (tv_get_number_chk(rettv, &error) != 0)
!               result = TRUE;
!           clear_tv(rettv);
!           if (error)
!               return FAIL;
        }
  
        /*
--- 2207,2225 ----
        evaluate = orig_flags & EVAL_EVALUATE;
        if (evaluate)
        {
!           if (vim9script)
!           {
!               result = tv2bool(rettv);
!           }
!           else
!           {
!               error = FALSE;
!               if (tv_get_number_chk(rettv, &error) != 0)
!                   result = TRUE;
!               clear_tv(rettv);
!               if (error)
!                   return FAIL;
!           }
        }
  
        /*
***************
*** 2236,2248 ****
             */
            if (evaluate && !result)
            {
!               if (tv_get_number_chk(&var2, &error) != 0)
!                   result = TRUE;
!               clear_tv(&var2);
!               if (error)
!                   return FAIL;
            }
!           if (evaluate)
            {
                rettv->v_type = VAR_NUMBER;
                rettv->vval.v_number = result;
--- 2244,2265 ----
             */
            if (evaluate && !result)
            {
!               if (vim9script)
!               {
!                   clear_tv(rettv);
!                   *rettv = var2;
!                   result = tv2bool(rettv);
!               }
!               else
!               {
!                   if (tv_get_number_chk(&var2, &error) != 0)
!                       result = TRUE;
!                   clear_tv(&var2);
!                   if (error)
!                       return FAIL;
!               }
            }
!           if (evaluate && !vim9script)
            {
                rettv->v_type = VAR_NUMBER;
                rettv->vval.v_number = result;
***************
*** 2294,2299 ****
--- 2311,2317 ----
        long        result = TRUE;
        typval_T    var2;
        int         error;
+       int         vim9script = in_vim9script();
  
        if (evalarg == NULL)
        {
***************
*** 2304,2315 ****
        evaluate = orig_flags & EVAL_EVALUATE;
        if (evaluate)
        {
!           error = FALSE;
!           if (tv_get_number_chk(rettv, &error) == 0)
!               result = FALSE;
!           clear_tv(rettv);
!           if (error)
!               return FAIL;
        }
  
        /*
--- 2322,2340 ----
        evaluate = orig_flags & EVAL_EVALUATE;
        if (evaluate)
        {
!           if (vim9script)
!           {
!               result = tv2bool(rettv);
!           }
!           else
!           {
!               error = FALSE;
!               if (tv_get_number_chk(rettv, &error) == 0)
!                   result = FALSE;
!               clear_tv(rettv);
!               if (error)
!                   return FAIL;
!           }
        }
  
        /*
***************
*** 2334,2346 ****
             */
            if (evaluate && result)
            {
!               if (tv_get_number_chk(&var2, &error) == 0)
!                   result = FALSE;
!               clear_tv(&var2);
!               if (error)
!                   return FAIL;
            }
!           if (evaluate)
            {
                rettv->v_type = VAR_NUMBER;
                rettv->vval.v_number = result;
--- 2359,2380 ----
             */
            if (evaluate && result)
            {
!               if (vim9script)
!               {
!                   clear_tv(rettv);
!                   *rettv = var2;
!                   result = tv2bool(rettv);
!               }
!               else
!               {
!                   if (tv_get_number_chk(&var2, &error) == 0)
!                       result = FALSE;
!                   clear_tv(&var2);
!                   if (error)
!                       return FAIL;
!               }
            }
!           if (evaluate && !vim9script)
            {
                rettv->v_type = VAR_NUMBER;
                rettv->vval.v_number = result;
*** ../vim-8.2.1204/src/testdir/test_vim9_expr.vim      2020-07-13 
21:59:25.391482336 +0200
--- src/testdir/test_vim9_expr.vim      2020-07-13 22:24:03.635604688 +0200
***************
*** 127,133 ****
  enddef
  
  def Test_expr2_vimscript()
!   " only checks line continuation
    let lines =<< trim END
        vim9script
        let var = 0
--- 127,133 ----
  enddef
  
  def Test_expr2_vimscript()
!   " check line continuation
    let lines =<< trim END
        vim9script
        let var = 0
***************
*** 141,147 ****
        let var = v:false
                        || v:true
                        || v:false
!       assert_equal(1, var)
    END
    CheckScriptSuccess(lines)
  
--- 141,147 ----
        let var = v:false
                        || v:true
                        || v:false
!       assert_equal(v:true, var)
    END
    CheckScriptSuccess(lines)
  
***************
*** 150,156 ****
        let var = v:false ||
                        v:true ||
                v:false
!       assert_equal(1, var)
    END
    CheckScriptSuccess(lines)
  enddef
--- 150,188 ----
        let var = v:false ||
                        v:true ||
                v:false
!       assert_equal(v:true, var)
!   END
!   CheckScriptSuccess(lines)
! 
!   " check keeping the value
!   lines =<< trim END
!       vim9script
!       assert_equal(2, 2 || 0)
!       assert_equal(7, 0 ||
!                       0 ||
!                       7)
!       assert_equal(0, 0 || 0)
!       assert_equal(0, 0
!                       || 0)
!       assert_equal('', 0 || '')
! 
!       g:vals = []
!       assert_equal(3, Record(3) || Record(1))
!       assert_equal([3], g:vals)
! 
!       g:vals = []
!       assert_equal(5, Record(0) || Record(5))
!       assert_equal([0, 5], g:vals)
! 
!       g:vals = []
!       assert_equal(4, Record(0)
!                         || Record(4)
!                         || Record(0))
!       assert_equal([0, 4], g:vals)
! 
!       g:vals = []
!       assert_equal(0, Record([]) || Record('') || Record(0))
!       assert_equal([[], '', 0], g:vals)
    END
    CheckScriptSuccess(lines)
  enddef
***************
*** 199,205 ****
  enddef
  
  def Test_expr3_vimscript()
!   " only checks line continuation
    let lines =<< trim END
        vim9script
        let var = 0
--- 231,237 ----
  enddef
  
  def Test_expr3_vimscript()
!   " check line continuation
    let lines =<< trim END
        vim9script
        let var = 0
***************
*** 213,219 ****
        let var = v:true
                        && v:true
                        && v:true
!       assert_equal(1, var)
    END
    CheckScriptSuccess(lines)
  
--- 245,251 ----
        let var = v:true
                        && v:true
                        && v:true
!       assert_equal(v:true, var)
    END
    CheckScriptSuccess(lines)
  
***************
*** 222,228 ****
        let var = v:true &&
                        v:true &&
                        v:true
!       assert_equal(1, var)
    END
    CheckScriptSuccess(lines)
  enddef
--- 254,296 ----
        let var = v:true &&
                        v:true &&
                        v:true
!       assert_equal(v:true, var)
!   END
!   CheckScriptSuccess(lines)
! 
!   " check keeping the value
!   lines =<< trim END
!       vim9script
!       assert_equal(0, 2 && 0)
!       assert_equal(0, 0 &&
!                   0 &&
!                   7)
!       assert_equal(7, 2
!                       && 3
!                       && 7)
!       assert_equal(0, 0 && 0)
!       assert_equal(0, 0 && '')
!       assert_equal('', 8 && '')
! 
!       g:vals = []
!       assert_equal(1, Record(3) && Record(1))
!       assert_equal([3, 1], g:vals)
! 
!       g:vals = []
!       assert_equal(0, Record(0) && Record(5))
!       assert_equal([0], g:vals)
! 
!       g:vals = []
!       assert_equal(0, Record(0) && Record(4) && Record(0))
!       assert_equal([0], g:vals)
! 
!       g:vals = []
!       assert_equal(0, Record(8) && Record(4) && Record(0))
!       assert_equal([8, 4, 0], g:vals)
! 
!       g:vals = []
!       assert_equal(0, Record([1]) && Record('z') && Record(0))
!       assert_equal([[1], 'z', 0], g:vals)
    END
    CheckScriptSuccess(lines)
  enddef
*** ../vim-8.2.1204/src/version.c       2020-07-13 21:59:25.391482336 +0200
--- src/version.c       2020-07-13 22:28:24.234903408 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1205,
  /**/

-- 
Bypasses are devices that allow some people to dash from point A to
point B very fast while other people dash from point B to point A very
fast.  People living at point C, being a point directly in between, are
often given to wonder what's so great about point A that so many people
from point B are so keen to get there and what's so great about point B
that so many people from point A are so keen to get there.  They often
wish that people would just once and for all work out where the hell
they wanted to be.
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202007132029.06DKTQp92844100%40masaka.moolenaar.net.

Raspunde prin e-mail lui