0
0
mirror of https://github.com/vim/vim.git synced 2025-10-06 05:44:14 -04:00

patch 8.1.0793: incorrect error messages for functions that take a Blob

Problem:    Incorrect error messages for functions that now take a Blob
            argument.
Solution:   Adjust the error messages. (Dominique Pelle, closes #3846)
This commit is contained in:
Bram Moolenaar
2019-01-22 22:20:38 +01:00
parent 9e26f7d31f
commit 0d17f0d1c0
6 changed files with 38 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.1. Last change: 2019 Jan 17 *eval.txt* For Vim version 8.1. Last change: 2019 Jan 21
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -38,7 +38,7 @@ done, the features in this document are not available. See |+eval| and
1. Variables *variables* 1. Variables *variables*
1.1 Variable types ~ 1.1 Variable types ~
*E712* *E712* *E896* *E897* *E898*
There are nine types of variables: There are nine types of variables:
Number A 32 or 64 bit signed number. |expr-number| *Number* Number A 32 or 64 bit signed number. |expr-number| *Number*
@@ -633,6 +633,9 @@ Blob creation ~
A Blob can be created with a |blob-literal|: > A Blob can be created with a |blob-literal|: >
:let b = 0zFF00ED015DAF :let b = 0zFF00ED015DAF
Dots can be inserted between bytes (pair of hex characters) for readability,
they don't change the value: >
:let b = 0zFF00.ED01.5DAF
A blob can be read from a file with |readfile()| passing the {type} argument A blob can be read from a file with |readfile()| passing the {type} argument
set to "B", for example: > set to "B", for example: >
@@ -3805,8 +3808,8 @@ escape({string}, {chars}) *escape()*
*eval()* *eval()*
eval({string}) Evaluate {string} and return the result. Especially useful to eval({string}) Evaluate {string} and return the result. Especially useful to
turn the result of |string()| back into the original value. turn the result of |string()| back into the original value.
This works for Numbers, Floats, Strings and composites of This works for Numbers, Floats, Strings, Blobs and composites
them. Also works for |Funcref|s that refer to existing of them. Also works for |Funcref|s that refer to existing
functions. functions.
eventhandler() *eventhandler()* eventhandler() *eventhandler()*
@@ -5700,7 +5703,11 @@ items({dict}) *items()*
Return a |List| with all the key-value pairs of {dict}. Each Return a |List| with all the key-value pairs of {dict}. Each
|List| item is a list with two items: the key of a {dict} |List| item is a list with two items: the key of a {dict}
entry and the value of this entry. The |List| is in arbitrary entry and the value of this entry. The |List| is in arbitrary
order. order. Also see |keys()| and |values()|.
Example: >
for [key, value] in items(mydict)
echo key . ': ' . value
endfor
job_getchannel({job}) *job_getchannel()* job_getchannel({job}) *job_getchannel()*
Get the channel handle that {job} is using. Get the channel handle that {job} is using.
@@ -5885,7 +5892,7 @@ json_decode({string}) *json_decode()*
- A trailing comma in an array and object is ignored, e.g. - A trailing comma in an array and object is ignored, e.g.
"[1, 2, ]" is the same as "[1, 2]". "[1, 2, ]" is the same as "[1, 2]".
- Integer keys are accepted in objects, e.g. {1:2} is the - Integer keys are accepted in objects, e.g. {1:2} is the
same as {'1':2}. same as {"1":2}.
- More floating point numbers are recognized, e.g. "1." for - More floating point numbers are recognized, e.g. "1." for
"1.0", or "001.2" for "1.2". Special floating point values "1.0", or "001.2" for "1.2". Special floating point values
"Infinity", "-Infinity" and "NaN" (capitalization ignored) "Infinity", "-Infinity" and "NaN" (capitalization ignored)
@@ -5897,6 +5904,8 @@ json_decode({string}) *json_decode()*
- Control characters U+0000 through U+001F which are not - Control characters U+0000 through U+001F which are not
escaped in strings are accepted, e.g. " " (tab escaped in strings are accepted, e.g. " " (tab
character in string) for "\t". character in string) for "\t".
- An empty JSON expression or made of only spaces is accepted
and results in v:none.
- Backslash in an invalid 2-character sequence escape is - Backslash in an invalid 2-character sequence escape is
ignored, e.g. "\a" is decoded as "a". ignored, e.g. "\a" is decoded as "a".
- A correct surrogate pair in JSON strings should normally be - A correct surrogate pair in JSON strings should normally be
@@ -5936,7 +5945,7 @@ json_encode({expr}) *json_encode()*
keys({dict}) *keys()* keys({dict}) *keys()*
Return a |List| with all the keys of {dict}. The |List| is in Return a |List| with all the keys of {dict}. The |List| is in
arbitrary order. arbitrary order. Also see |items()| and |values()|.
*len()* *E701* *len()* *E701*
len({expr}) The result is a Number, which is the length of the argument. len({expr}) The result is a Number, which is the length of the argument.
@@ -8617,13 +8626,14 @@ stridx({haystack}, {needle} [, {start}]) *stridx()*
*string()* *string()*
string({expr}) Return {expr} converted to a String. If {expr} is a Number, string({expr}) Return {expr} converted to a String. If {expr} is a Number,
Float, String or a composition of them, then the result can be Float, String, Blob or a composition of them, then the result
parsed back with |eval()|. can be parsed back with |eval()|.
{expr} type result ~ {expr} type result ~
String 'string' (single quotes are doubled) String 'string' (single quotes are doubled)
Number 123 Number 123
Float 123.123456 or 1.123456e8 Float 123.123456 or 1.123456e8
Funcref function('name') Funcref function('name')
Blob 0z00112233.44556677.8899
List [item, item] List [item, item]
Dictionary {key: value, key: value} Dictionary {key: value, key: value}
@@ -9778,7 +9788,7 @@ uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
values({dict}) *values()* values({dict}) *values()*
Return a |List| with all the values of {dict}. The |List| is Return a |List| with all the values of {dict}. The |List| is
in arbitrary order. in arbitrary order. Also see |items()| and |keys()|.
virtcol({expr}) *virtcol()* virtcol({expr}) *virtcol()*

View File

@@ -29,6 +29,7 @@
#endif #endif
static char *e_listarg = N_("E686: Argument of %s must be a List"); static char *e_listarg = N_("E686: Argument of %s must be a List");
static char *e_listblobarg = N_("E898: Argument of %s must be a List or Blob");
static char *e_stringreq = N_("E928: String required"); static char *e_stringreq = N_("E928: String required");
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
@@ -1269,7 +1270,7 @@ f_add(typval_T *argvars, typval_T *rettv)
} }
} }
else else
emsg(_(e_listreq)); emsg(_(e_listblobreq));
} }
/* /*
@@ -4490,7 +4491,7 @@ f_get(typval_T *argvars, typval_T *rettv)
} }
} }
else else
semsg(_(e_listdictarg), "get()"); semsg(_(e_listdictblobarg), "get()");
if (tv == NULL) if (tv == NULL)
{ {
@@ -7057,7 +7058,7 @@ f_index(typval_T *argvars, typval_T *rettv)
} }
else if (argvars[0].v_type != VAR_LIST) else if (argvars[0].v_type != VAR_LIST)
{ {
emsg(_(e_listreq)); emsg(_(e_listblobreq));
return; return;
} }
@@ -7281,7 +7282,7 @@ f_insert(typval_T *argvars, typval_T *rettv)
copy_tv(&argvars[0], rettv); copy_tv(&argvars[0], rettv);
} }
else if (argvars[0].v_type != VAR_LIST) else if (argvars[0].v_type != VAR_LIST)
semsg(_(e_listarg), "insert()"); semsg(_(e_listblobarg), "insert()");
else if ((l = argvars[0].vval.v_list) != NULL && !tv_check_lock(l->lv_lock, else if ((l = argvars[0].vval.v_list) != NULL && !tv_check_lock(l->lv_lock,
(char_u *)N_("insert() argument"), TRUE)) (char_u *)N_("insert() argument"), TRUE))
{ {
@@ -9789,7 +9790,7 @@ f_remove(typval_T *argvars, typval_T *rettv)
} }
} }
else if (argvars[0].v_type != VAR_LIST) else if (argvars[0].v_type != VAR_LIST)
semsg(_(e_listdictarg), "remove()"); semsg(_(e_listdictblobarg), "remove()");
else if ((l = argvars[0].vval.v_list) != NULL else if ((l = argvars[0].vval.v_list) != NULL
&& !tv_check_lock(l->lv_lock, arg_errmsg, TRUE)) && !tv_check_lock(l->lv_lock, arg_errmsg, TRUE))
{ {
@@ -10136,7 +10137,7 @@ f_reverse(typval_T *argvars, typval_T *rettv)
} }
if (argvars[0].v_type != VAR_LIST) if (argvars[0].v_type != VAR_LIST)
semsg(_(e_listarg), "reverse()"); semsg(_(e_listblobarg), "reverse()");
else if ((l = argvars[0].vval.v_list) != NULL else if ((l = argvars[0].vval.v_list) != NULL
&& !tv_check_lock(l->lv_lock, && !tv_check_lock(l->lv_lock,
(char_u *)N_("reverse() argument"), TRUE)) (char_u *)N_("reverse() argument"), TRUE))

View File

@@ -1521,7 +1521,9 @@ EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob"));
EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s")); EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s"));
EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s")); EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s"));
EXTERN char e_listreq[] INIT(= N_("E714: List required")); EXTERN char e_listreq[] INIT(= N_("E714: List required"));
EXTERN char e_listblobreq[] INIT(= N_("E897: List or Blob required"));
EXTERN char e_listdictarg[] INIT(= N_("E712: Argument of %s must be a List or Dictionary")); EXTERN char e_listdictarg[] INIT(= N_("E712: Argument of %s must be a List or Dictionary"));
EXTERN char e_listdictblobarg[] INIT(= N_("E896: Argument of %s must be a List, Dictionary or Blob"));
#endif #endif
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
EXTERN char e_readerrf[] INIT(= N_("E47: Error while reading errorfile")); EXTERN char e_readerrf[] INIT(= N_("E47: Error while reading errorfile"));

View File

@@ -32,6 +32,7 @@ func Test_blob_create()
call assert_fails('let b = 0z1.1') call assert_fails('let b = 0z1.1')
call assert_fails('let b = 0z.') call assert_fails('let b = 0z.')
call assert_fails('let b = 0z001122.') call assert_fails('let b = 0z001122.')
call assert_fails('call get("", 1)', 'E896:')
endfunc endfunc
" assignment to a blob " assignment to a blob
@@ -182,6 +183,7 @@ func Test_blob_add()
call assert_equal(0z00112233, b) call assert_equal(0z00112233, b)
call assert_fails('call add(b, [9])', 'E745:') call assert_fails('call add(b, [9])', 'E745:')
call assert_fails('call add("", 0x01)', 'E897:')
endfunc endfunc
func Test_blob_empty() func Test_blob_empty()
@@ -219,7 +221,7 @@ func Test_blob_func_remove()
call assert_fails("call remove(b, 5)", 'E979:') call assert_fails("call remove(b, 5)", 'E979:')
call assert_fails("call remove(b, 1, 5)", 'E979:') call assert_fails("call remove(b, 1, 5)", 'E979:')
call assert_fails("call remove(b, 3, 2)", 'E979:') call assert_fails("call remove(b, 3, 2)", 'E979:')
call assert_fails("call remove(1, 0)", 'E712:') call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(b, b)", 'E974:') call assert_fails("call remove(b, b)", 'E974:')
endfunc endfunc
@@ -255,7 +257,7 @@ func Test_blob_index()
call assert_equal(2, index(0z11111111, 0x11, -2)) call assert_equal(2, index(0z11111111, 0x11, -2))
call assert_equal(3, index(0z11110111, 0x11, -2)) call assert_equal(3, index(0z11110111, 0x11, -2))
call assert_fails('call index("asdf", 0)', 'E714:') call assert_fails('call index("asdf", 0)', 'E897:')
endfunc endfunc
func Test_blob_insert() func Test_blob_insert()

View File

@@ -139,7 +139,7 @@ func Test_list_func_remove()
call assert_fails("call remove(l, 5)", 'E684:') call assert_fails("call remove(l, 5)", 'E684:')
call assert_fails("call remove(l, 1, 5)", 'E684:') call assert_fails("call remove(l, 1, 5)", 'E684:')
call assert_fails("call remove(l, 3, 2)", 'E16:') call assert_fails("call remove(l, 3, 2)", 'E16:')
call assert_fails("call remove(1, 0)", 'E712:') call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(l, l)", 'E745:') call assert_fails("call remove(l, l)", 'E745:')
endfunc endfunc
@@ -596,6 +596,8 @@ func Test_reverse_sort_uniq()
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1)) call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1))
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i')) call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i'))
call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l))) call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
call assert_fails('call reverse("")', 'E898:')
endfunc endfunc
" splitting a string to a List " splitting a string to a List

View File

@@ -791,6 +791,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
793,
/**/ /**/
792, 792,
/**/ /**/