To: vim_dev@googlegroups.com Subject: Patch 8.2.3646 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3646 Problem: Using in a function gives an unexpected result. Solution: Give an error in a Vim9 function. (issue #9189) Files: src/scriptfile.c, src/errors.h, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.3645/src/scriptfile.c 2021-06-11 21:21:20.715944455 +0100 --- src/scriptfile.c 2021-11-22 15:34:41.537050133 +0000 *************** *** 135,140 **** --- 135,154 ---- return vim_strsave(entry->es_name); } #ifdef FEAT_EVAL + // expand('') works in a function for backwards compatibility, but + // may give an unexpected result. Disallow it in Vim 9 script. + if (which == ESTACK_SFILE && in_vim9script()) + { + int save_emsg_off = emsg_off; + + if (emsg_off == 1) + // f_expand() silences errors but we do want this one + emsg_off = 0; + emsg(_(e_cannot_expand_sfile_in_vim9_function)); + emsg_off = save_emsg_off; + return NULL; + } + // Give information about each stack entry up to the root. // For a function we compose the call stack, as it was done in the past: // "function One[123]..Two[456]..Three" *** ../vim-8.2.3645/src/errors.h 2021-10-24 20:34:01.434895238 +0100 --- src/errors.h 2021-11-22 15:22:23.500910889 +0000 *************** *** 684,686 **** --- 684,688 ---- INIT(= N_("E1243: ASCII code not in 32-127 range")); EXTERN char e_bad_color_string_str[] INIT(= N_("E1244: Bad color string: %s")); + EXTERN char e_cannot_expand_sfile_in_vim9_function[] + INIT(= N_("E1245: Cannot expand in a Vim9 function")); *** ../vim-8.2.3645/src/testdir/test_vim9_builtin.vim 2021-11-16 17:19:24.506463307 +0000 --- src/testdir/test_vim9_builtin.vim 2021-11-22 15:28:49.098399879 +0000 *************** *** 915,920 **** --- 915,928 ---- CheckDefAndScriptFailure2(['expand("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') CheckDefAndScriptFailure2(['expand("a", true, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') expand('')->assert_equal('') + + var caught = false + try + echo expand("") + catch /E1245:/ + caught = true + endtry + assert_true(caught) enddef def Test_expandcmd() *** ../vim-8.2.3645/src/version.c 2021-11-22 15:05:42.713617025 +0000 --- src/version.c 2021-11-22 15:36:33.236728037 +0000 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 3646, /**/ -- VOICE OVER: As the horrendous Black Beast lunged forward, escape for Arthur and his knights seemed hopeless, when, suddenly ... the animator suffered a fatal heart attack. ANIMATOR: Aaaaagh! VOICE OVER: The cartoon peril was no more ... The Quest for Holy Grail could continue. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///