mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 23:38:17 +00:00
eval: Port parts of 7.4.1267 that are not already present
This commit is contained in:
@@ -99,6 +99,8 @@ are always available and may be used simultaneously in separate plugins. The
|
||||
error out.
|
||||
4. Stringifyed infinite and NaN values now use |str2float()| and can be evaled
|
||||
back.
|
||||
5. (internal) Trying to print or stringify VAR_UNKNOWN in Vim results in
|
||||
nothing, |E908|, in Neovim it is internal error.
|
||||
|
||||
|jsondecode()| behaviour changed:
|
||||
1. It may output |msgpack-special-dict|.
|
||||
|
@@ -4319,19 +4319,37 @@ eval_index (
|
||||
char_u *s;
|
||||
char_u *key = NULL;
|
||||
|
||||
if (rettv->v_type == VAR_FUNC) {
|
||||
if (verbose)
|
||||
EMSG(_("E695: Cannot index a Funcref"));
|
||||
return FAIL;
|
||||
} else if (rettv->v_type == VAR_FLOAT) {
|
||||
if (verbose)
|
||||
EMSG(_(e_float_as_string));
|
||||
return FAIL;
|
||||
} else if (rettv->v_type == VAR_SPECIAL) {
|
||||
if (verbose) {
|
||||
EMSG(_("E15: Cannot index a special value"));
|
||||
switch (rettv->v_type) {
|
||||
case VAR_FUNC: {
|
||||
if (verbose) {
|
||||
EMSG(_("E695: Cannot index a Funcref"));
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
case VAR_FLOAT: {
|
||||
if (verbose) {
|
||||
EMSG(_(e_float_as_string));
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
case VAR_SPECIAL: {
|
||||
if (verbose) {
|
||||
EMSG(_("E909: Cannot index a special variable"));
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
case VAR_UNKNOWN: {
|
||||
if (evaluate) {
|
||||
return FAIL;
|
||||
}
|
||||
// fallthrough
|
||||
}
|
||||
case VAR_STRING:
|
||||
case VAR_NUMBER:
|
||||
case VAR_LIST:
|
||||
case VAR_DICT: {
|
||||
break;
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
init_tv(&var1);
|
||||
@@ -4522,11 +4540,11 @@ eval_index (
|
||||
*rettv = var1;
|
||||
}
|
||||
break;
|
||||
case VAR_SPECIAL:
|
||||
case VAR_FUNC:
|
||||
case VAR_FLOAT:
|
||||
case VAR_UNKNOWN:
|
||||
case VAR_SPECIAL:
|
||||
assert(false);
|
||||
break; // Not evaluating, skipping over subscript
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5076,11 +5094,12 @@ tv_equal (
|
||||
return tv1->vval.v_special == tv2->vval.v_special;
|
||||
|
||||
case VAR_UNKNOWN:
|
||||
break;
|
||||
// VAR_UNKNOWN can be the result of an invalid expression, let’s say it does
|
||||
// not equal anything, not even self.
|
||||
return false;
|
||||
}
|
||||
|
||||
EMSG2(_(e_intern2), "tv_equal()");
|
||||
return TRUE;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -8516,7 +8535,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv)
|
||||
*/
|
||||
static void f_empty(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
int n;
|
||||
bool n;
|
||||
|
||||
switch (argvars[0].v_type) {
|
||||
case VAR_STRING:
|
||||
@@ -8542,8 +8561,9 @@ static void f_empty(typval_T *argvars, typval_T *rettv)
|
||||
n = argvars[0].vval.v_special != kSpecialVarTrue;
|
||||
break;
|
||||
case VAR_UNKNOWN:
|
||||
EMSG2(_(e_intern2), "f_empty()");
|
||||
n = 0;
|
||||
EMSG2(_(e_intern2), "f_empty(UNKNOWN)");
|
||||
n = true;
|
||||
break;
|
||||
}
|
||||
|
||||
rettv->vval.v_number = n;
|
||||
@@ -11641,7 +11661,10 @@ static void f_len(typval_T *argvars, typval_T *rettv)
|
||||
case VAR_DICT:
|
||||
rettv->vval.v_number = dict_len(argvars[0].vval.v_dict);
|
||||
break;
|
||||
default:
|
||||
case VAR_UNKNOWN:
|
||||
case VAR_SPECIAL:
|
||||
case VAR_FLOAT:
|
||||
case VAR_FUNC:
|
||||
EMSG(_("E701: Invalid type for len()"));
|
||||
break;
|
||||
}
|
||||
@@ -16215,7 +16238,11 @@ static void f_type(typval_T *argvars, typval_T *rettv)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VAR_UNKNOWN: EMSG2(_(e_intern2), "f_type()"); n = 0; break;
|
||||
case VAR_UNKNOWN: {
|
||||
EMSG2(_(e_intern2), "f_type(UNKNOWN)");
|
||||
n = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rettv->vval.v_number = n;
|
||||
}
|
||||
@@ -17529,7 +17556,7 @@ long get_tv_number_chk(typval_T *varp, int *denote)
|
||||
}
|
||||
break;
|
||||
case VAR_UNKNOWN:
|
||||
EMSG2(_(e_intern2), "get_tv_number()");
|
||||
EMSG2(_(e_intern2), "get_tv_number(UNKNOWN)");
|
||||
break;
|
||||
}
|
||||
if (denote == NULL) {
|
||||
@@ -17638,7 +17665,7 @@ static char_u *get_tv_string_buf_chk(const typval_T *varp, char_u *buf)
|
||||
STRCPY(buf, encode_special_var_names[varp->vval.v_special]);
|
||||
return buf;
|
||||
case VAR_UNKNOWN:
|
||||
EMSG2(_(e_intern2), "get_tv_string_buf()");
|
||||
EMSG(_("E908: using an invalid value as a String"));
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
@@ -18212,7 +18239,7 @@ void copy_tv(typval_T *from, typval_T *to)
|
||||
}
|
||||
break;
|
||||
case VAR_UNKNOWN:
|
||||
EMSG2(_(e_intern2), "copy_tv()");
|
||||
EMSG2(_(e_intern2), "copy_tv(UNKNOWN)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -18301,7 +18328,7 @@ int var_item_copy(const vimconv_T *const conv,
|
||||
ret = FAIL;
|
||||
break;
|
||||
case VAR_UNKNOWN:
|
||||
EMSG2(_(e_intern2), "var_item_copy()");
|
||||
EMSG2(_(e_intern2), "var_item_copy(UNKNOWN)");
|
||||
ret = FAIL;
|
||||
}
|
||||
--recurse;
|
||||
|
@@ -95,7 +95,7 @@ static int included_patches[] = {
|
||||
// 1270
|
||||
// 1269
|
||||
// 1268
|
||||
// 1267
|
||||
1267,
|
||||
// 1266
|
||||
// 1265
|
||||
// 1264
|
||||
|
@@ -147,9 +147,9 @@ describe('Special values', function()
|
||||
end)
|
||||
|
||||
it('fails in index', function()
|
||||
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:true[0]'))
|
||||
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:false[0]'))
|
||||
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:null[0]'))
|
||||
eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:true[0]'))
|
||||
eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:false[0]'))
|
||||
eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:null[0]'))
|
||||
end)
|
||||
|
||||
it('is accepted by assert_true and assert_false', function()
|
||||
|
Reference in New Issue
Block a user