]> granicus.if.org Git - vim/commitdiff
patch 7.4.1163 v7.4.1163
authorBram Moolenaar <Bram@vim.org>
Sun, 24 Jan 2016 13:22:10 +0000 (14:22 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 24 Jan 2016 13:22:10 +0000 (14:22 +0100)
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)

src/eval.c
src/testdir/test_viml.vim
src/version.c

index 751c608431a4948f53959a297afe0898f28d1453..b4cb3852abb9bc32f7a6b5d80a49b1977bb4b127 100644 (file)
@@ -7820,6 +7820,20 @@ failret:
     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,14 +7928,7 @@ echo_string(tv, tofree, numbuf, copyID)
 
        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)");
-           }
+           r = (char_u *)get_var_special_name(tv->vval.v_number);
            break;
 
        default:
@@ -21704,6 +21711,9 @@ get_tv_number_chk(varp, denote)
        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,6 +21869,10 @@ get_tv_string_buf_chk(varp, buf)
            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;
index 39c0667b81409b9aeedaf22e2e86612a60a4051c..f1a7cb43517b8348440325e97545f1fe3dbe8bb4 100644 (file)
@@ -936,6 +936,16 @@ func Test_type()
     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
 
 "-------------------------------------------------------------------------------
index 9d5e9840df7080ab11f0b674ba209cdbc25f2607..60cb07c34807da39c8fba446ff5afe954839b277 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1163,
 /**/
     1162,
 /**/