summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-01-24 14:22:10 +0100
committerBram Moolenaar <Bram@vim.org>2016-01-24 14:22:10 +0100
commit17a13437c9414a8693369a97f3be2fc8ad48c12e (patch)
treea1250326988b8caa9aebee164dd7f53392682d63
parent9e3be26872307f9c53a9f37647a659091bdffb1f (diff)
downloadvim-git-17a13437c9414a8693369a97f3be2fc8ad48c12e.tar.gz
patch 7.4.1163v7.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)
-rw-r--r--src/eval.c30
-rw-r--r--src/testdir/test_viml.vim10
-rw-r--r--src/version.c2
3 files changed, 34 insertions, 8 deletions
diff --git a/src/eval.c b/src/eval.c
index 751c60843..b4cb3852a 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
diff --git a/src/testdir/test_viml.vim b/src/testdir/test_viml.vim
index 39c0667b8..f1a7cb435 100644
--- a/src/testdir/test_viml.vim
+++ b/src/testdir/test_viml.vim
@@ -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
"-------------------------------------------------------------------------------
diff --git a/src/version.c b/src/version.c
index 9d5e9840d..60cb07c34 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1163,
+/**/
1162,
/**/
1161,