To: vim_dev@googlegroups.com Subject: Patch 8.2.2488 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2488 Problem: json_encode() gives generic argument error. Solution: Mention the type that can't be encoded. (issue #7802) Files: src/json.c, src/errors.h, src/testdir/test_json.vim *** ../vim-8.2.2487/src/json.c 2020-07-23 17:16:15.050100601 +0200 --- src/json.c 2021-02-08 21:42:42.219025217 +0100 *************** *** 230,237 **** case VAR_PARTIAL: case VAR_JOB: case VAR_CHANNEL: ! // no JSON equivalent TODO: better error ! emsg(_(e_invarg)); return FAIL; case VAR_BLOB: --- 230,236 ---- case VAR_PARTIAL: case VAR_JOB: case VAR_CHANNEL: ! semsg(_(e_cannot_json_encode_str), vartype_name(val->v_type)); return FAIL; case VAR_BLOB: *** ../vim-8.2.2487/src/errors.h 2021-02-07 18:06:25.266692335 +0100 --- src/errors.h 2021-02-08 21:47:24.746217185 +0100 *************** *** 357,359 **** --- 357,361 ---- INIT(= N_("E1159: Cannot split a window when closing the buffer")); EXTERN char e_cannot_use_default_for_variable_arguments[] INIT(= N_("E1160: Cannot use a default for variable arguments")); + EXTERN char e_cannot_json_encode_str[] + INIT(= N_("E1161: Cannot json encode a %s")); *** ../vim-8.2.2487/src/testdir/test_json.vim 2020-10-19 13:12:29.844428375 +0200 --- src/testdir/test_json.vim 2021-02-08 21:52:28.649113228 +0100 *************** *** 107,114 **** call assert_equal('"café"', json_encode("caf\xe9")) let &encoding = save_encoding ! call assert_fails('echo json_encode(function("tr"))', 'E474:') ! call assert_fails('echo json_encode([function("tr")])', 'E474:') call assert_equal('{"a":""}', json_encode({'a': test_null_string()})) call assert_equal('{"a":[]}', json_encode({"a": test_null_list()})) --- 107,114 ---- call assert_equal('"café"', json_encode("caf\xe9")) let &encoding = save_encoding ! call assert_fails('echo json_encode(function("tr"))', 'E1161: Cannot json encode a func') ! call assert_fails('echo json_encode([function("tr")])', 'E1161: Cannot json encode a func') call assert_equal('{"a":""}', json_encode({'a': test_null_string()})) call assert_equal('{"a":[]}', json_encode({"a": test_null_list()})) *************** *** 246,253 **** call assert_equal(s:jsonvals, js_encode(s:varvals)) ! call assert_fails('echo js_encode(function("tr"))', 'E474:') ! call assert_fails('echo js_encode([function("tr")])', 'E474:') silent! let res = js_encode(function("tr")) call assert_equal("", res) --- 246,253 ---- call assert_equal(s:jsonvals, js_encode(s:varvals)) ! call assert_fails('echo js_encode(function("tr"))', 'E1161: Cannot json encode a func') ! call assert_fails('echo js_encode([function("tr")])', 'E1161: Cannot json encode a func') silent! let res = js_encode(function("tr")) call assert_equal("", res) *** ../vim-8.2.2487/src/version.c 2021-02-08 21:28:53.825440827 +0100 --- src/version.c 2021-02-08 21:44:02.738794489 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2488, /**/ -- DEAD PERSON: I don't want to go in the cart! CUSTOMER: Oh, don't be such a baby. MORTICIAN: I can't take him... DEAD PERSON: I feel fine! CUSTOMER: Oh, do us a favor... MORTICIAN: I can't. The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///