mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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)
This commit is contained in:
30
src/eval.c
30
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;
|
||||
|
@@ -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
|
||||
|
||||
"-------------------------------------------------------------------------------
|
||||
|
@@ -741,6 +741,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1163,
|
||||
/**/
|
||||
1162,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user