Patch 7.4.1163
Problem:    Expressions "0 + v:true" and "'' . v:true" cause an error.
Solution:   Return something sensible when using a special variable as a
            number or as a string. (suggested by Damien)
Files:      src/eval.c, src/testdir/test_viml.vim


*** ../vim-7.4.1162/src/eval.c  2016-01-23 22:17:26.878246531 +0100
--- src/eval.c  2016-01-24 14:14:06.827601895 +0100
***************
*** 7820,7825 ****
--- 7820,7839 ----
      return OK;
  }
  
+     static char *
+ get_var_special_name(int nr)
+ {
+     switch (nr)
+     {
+       case VVAL_FALSE: return "false";
+       case VVAL_TRUE: return "true";
+       case VVAL_NONE: return "none";
+       case VVAL_NULL: return "null";
+     }
+     EMSG2(_(e_intern2), "get_var_special_name()");
+     return "42";
+ }
+ 
  /*
   * Return a string with the string representation of a variable.
   * If the memory is allocated "tofree" is set to it, otherwise NULL.
***************
*** 7914,7927 ****
  
        case VAR_SPECIAL:
            *tofree = NULL;
!           switch (tv->vval.v_number)
!           {
!               case VVAL_FALSE: r = (char_u *)"false"; break;
!               case VVAL_TRUE: r = (char_u *)"true"; break;
!               case VVAL_NONE: r = (char_u *)"none"; break;
!               case VVAL_NULL: r = (char_u *)"null"; break;
!               default: EMSG2(_(e_intern2), "echo_string(special)");
!           }
            break;
  
        default:
--- 7928,7934 ----
  
        case VAR_SPECIAL:
            *tofree = NULL;
!           r = (char_u *)get_var_special_name(tv->vval.v_number);
            break;
  
        default:
***************
*** 21704,21709 ****
--- 21711,21719 ----
        case VAR_DICT:
            EMSG(_("E728: Using a Dictionary as a Number"));
            break;
+       case VAR_SPECIAL:
+           return varp->vval.v_number == VVAL_TRUE ? 1 : 0;
+           break;
        default:
            EMSG2(_(e_intern2), "get_tv_number()");
            break;
***************
*** 21859,21864 ****
--- 21869,21878 ----
            if (varp->vval.v_string != NULL)
                return varp->vval.v_string;
            return (char_u *)"";
+       case VAR_SPECIAL:
+           STRCPY(buf, get_var_special_name(varp->vval.v_number));
+           return buf;
+ 
        default:
            EMSG2(_(e_intern2), "get_tv_string_buf()");
            break;
*** ../vim-7.4.1162/src/testdir/test_viml.vim   2016-01-23 21:59:47.569792161 
+0100
--- src/testdir/test_viml.vim   2016-01-24 14:15:28.418758643 +0100
***************
*** 936,941 ****
--- 936,951 ----
      call assert_equal(6, type(v:true))
      call assert_equal(7, type(v:none))
      call assert_equal(7, type(v:null))
+ 
+     call assert_equal(0, 0 + v:false)
+     call assert_equal(1, 0 + v:true)
+     call assert_equal(0, 0 + v:none)
+     call assert_equal(0, 0 + v:null)
+ 
+     call assert_equal('false', '' . v:false)
+     call assert_equal('true', '' . v:true)
+     call assert_equal('none', '' . v:none)
+     call assert_equal('null', '' . v:null)
  endfunc
  
  
"-------------------------------------------------------------------------------
*** ../vim-7.4.1162/src/version.c       2016-01-24 13:58:36.697212302 +0100
--- src/version.c       2016-01-24 14:16:09.614333075 +0100
***************
*** 743,744 ****
--- 743,746 ----
  {   /* Add new patch number below this line */
+ /**/
+     1163,
  /**/

-- 
"Space is big.  Really big.  You just won't believe how vastly hugely mind-
bogglingly big it is.  I mean, you may think it's a long way down the
road to the chemist, but that's just peanuts to space."
                -- 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].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui