# HG changeset patch # User Bram Moolenaar # Date 1548192606 -3600 # Node ID 4af72c72409359cbe19b94c43591bb97677307f0 # Parent 78c9cce2bac99cf0b5a834d1cb8092402cb1fdbb patch 8.1.0793: incorrect error messages for functions that take a Blob commit https://github.com/vim/vim/commit/0d17f0d1c09fa6db306336695ba646c21ea24909 Author: Bram Moolenaar Date: Tue Jan 22 22:20:38 2019 +0100 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) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -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 @@ -38,7 +38,7 @@ 13. Testing |testing| 1. Variables *variables* 1.1 Variable types ~ - *E712* + *E712* *E896* *E897* *E898* There are nine types of variables: 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|: > :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 set to "B", for example: > @@ -3805,8 +3808,8 @@ escape({string}, {chars}) *escape()* *eval()* eval({string}) Evaluate {string} and return the result. Especially useful to turn the result of |string()| back into the original value. - This works for Numbers, Floats, Strings and composites of - them. Also works for |Funcref|s that refer to existing + This works for Numbers, Floats, Strings, Blobs and composites + of them. Also works for |Funcref|s that refer to existing functions. eventhandler() *eventhandler()* @@ -5700,7 +5703,11 @@ items({dict}) *items()* 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} 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()* 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. "[1, 2, ]" is the same as "[1, 2]". - 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 "1.0", or "001.2" for "1.2". Special floating point values "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 escaped in strings are accepted, e.g. " " (tab 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 ignored, e.g. "\a" is decoded as "a". - A correct surrogate pair in JSON strings should normally be @@ -5936,7 +5945,7 @@ json_encode({expr}) *json_encode()* keys({dict}) *keys()* 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({expr}) The result is a Number, which is the length of the argument. @@ -8617,13 +8626,14 @@ stridx({haystack}, {needle} [, {start}]) *string()* 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 - parsed back with |eval()|. + Float, String, Blob or a composition of them, then the result + can be parsed back with |eval()|. {expr} type result ~ String 'string' (single quotes are doubled) Number 123 Float 123.123456 or 1.123456e8 Funcref function('name') + Blob 0z00112233.44556677.8899 List [item, item] Dictionary {key: value, key: value} @@ -9778,7 +9788,7 @@ uniq({list} [, {func} [, {dict}]]) *un values({dict}) *values()* 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()* diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -29,6 +29,7 @@ #endif 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"); #ifdef FEAT_FLOAT @@ -1269,7 +1270,7 @@ f_add(typval_T *argvars, typval_T *rettv } } else - emsg(_(e_listreq)); + emsg(_(e_listblobreq)); } /* @@ -4490,7 +4491,7 @@ f_get(typval_T *argvars, typval_T *rettv } } else - semsg(_(e_listdictarg), "get()"); + semsg(_(e_listdictblobarg), "get()"); if (tv == NULL) { @@ -7057,7 +7058,7 @@ f_index(typval_T *argvars, typval_T *ret } else if (argvars[0].v_type != VAR_LIST) { - emsg(_(e_listreq)); + emsg(_(e_listblobreq)); return; } @@ -7281,7 +7282,7 @@ f_insert(typval_T *argvars, typval_T *re copy_tv(&argvars[0], rettv); } 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, (char_u *)N_("insert() argument"), TRUE)) { @@ -9789,7 +9790,7 @@ f_remove(typval_T *argvars, typval_T *re } } 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 && !tv_check_lock(l->lv_lock, arg_errmsg, TRUE)) { @@ -10136,7 +10137,7 @@ f_reverse(typval_T *argvars, typval_T *r } if (argvars[0].v_type != VAR_LIST) - semsg(_(e_listarg), "reverse()"); + semsg(_(e_listblobarg), "reverse()"); else if ((l = argvars[0].vval.v_list) != NULL && !tv_check_lock(l->lv_lock, (char_u *)N_("reverse() argument"), TRUE)) diff --git a/src/globals.h b/src/globals.h --- a/src/globals.h +++ b/src/globals.h @@ -1521,7 +1521,9 @@ EXTERN char e_invalblob[] INIT(= N_("E97 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_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_listdictblobarg[] INIT(= N_("E896: Argument of %s must be a List, Dictionary or Blob")); #endif #ifdef FEAT_QUICKFIX EXTERN char e_readerrf[] INIT(= N_("E47: Error while reading errorfile")); diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim --- a/src/testdir/test_blob.vim +++ b/src/testdir/test_blob.vim @@ -32,6 +32,7 @@ func Test_blob_create() call assert_fails('let b = 0z1.1') call assert_fails('let b = 0z.') call assert_fails('let b = 0z001122.') + call assert_fails('call get("", 1)', 'E896:') endfunc " assignment to a blob @@ -182,6 +183,7 @@ func Test_blob_add() call assert_equal(0z00112233, b) call assert_fails('call add(b, [9])', 'E745:') + call assert_fails('call add("", 0x01)', 'E897:') endfunc 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, 1, 5)", '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:') endfunc @@ -255,7 +257,7 @@ func Test_blob_index() call assert_equal(2, index(0z11111111, 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 func Test_blob_insert() diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim --- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -139,7 +139,7 @@ func Test_list_func_remove() call assert_fails("call remove(l, 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(1, 0)", 'E712:') + call assert_fails("call remove(1, 0)", 'E896:') call assert_fails("call remove(l, l)", 'E745:') 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), '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_fails('call reverse("")', 'E898:') endfunc " splitting a string to a List diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -792,6 +792,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 793, +/**/ 792, /**/ 791,