]> granicus.if.org Git - vim/commitdiff
patch 8.1.0793: incorrect error messages for functions that take a Blob v8.1.0793
authorBram Moolenaar <Bram@vim.org>
Tue, 22 Jan 2019 21:20:38 +0000 (22:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 22 Jan 2019 21:20:38 +0000 (22:20 +0100)
Problem:    Incorrect error messages for functions that now take a Blob
            argument.
Solution:   Adjust the error messages. (Dominique Pelle, closes #3846)

runtime/doc/eval.txt
src/evalfunc.c
src/globals.h
src/testdir/test_blob.vim
src/testdir/test_listdict.vim
src/version.c

index 93958d174ed20d41513e44ab92a285fa842d8aec..325676dbd40d18bfea0f5eacb2796998101d724f 100644 (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
@@ -38,7 +38,7 @@ done, the features in this document are not available.  See |+eval| and
 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}])                *stridx()*
 
                                                        *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}]])                        *uniq()* *E882*
 
 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()*
index ac009e6e9a21205fa8ca5011461c4e16fbff015e..11884abe7f1e9e7304feda6292d61ee90cd2307c 100644 (file)
@@ -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 *rettv)
     }
     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 *rettv)
        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 *rettv)
        }
     }
     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 *rettv)
     }
 
     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))
index d9cd467cac3b3efc743466379404fe132474358f..ef3764c824b0d9f05f297d36440022e171a91c37 100644 (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_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"));
index 1feab34150d034c1140d9541447bda1268828a71..964ed22799cad75b5552db673e672650b61b4344 100644 (file)
@@ -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()
index 19f137357971735ac580abc8fbe54b6c52028fdb..6c90cbc1b356602818cb05d663633773d1538f11 100644 (file)
@@ -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
index 0aa15d72ebb1c3cc45705cdc66014f7f71080734..cef2e4b5c563d64ed639762ac203825775c3326b 100644 (file)
@@ -791,6 +791,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    793,
 /**/
     792,
 /**/