mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Problem: Using <sfile> in a function gives an unexpected result. Solution: Give an error in a Vim9 function. (issue #9189)
This commit is contained in:
parent
7d5b8becc3
commit
c449271f4e
@ -684,3 +684,5 @@ EXTERN char e_ascii_code_not_in_range[]
|
|||||||
INIT(= N_("E1243: ASCII code not in 32-127 range"));
|
INIT(= N_("E1243: ASCII code not in 32-127 range"));
|
||||||
EXTERN char e_bad_color_string_str[]
|
EXTERN char e_bad_color_string_str[]
|
||||||
INIT(= N_("E1244: Bad color string: %s"));
|
INIT(= N_("E1244: Bad color string: %s"));
|
||||||
|
EXTERN char e_cannot_expand_sfile_in_vim9_function[]
|
||||||
|
INIT(= N_("E1245: Cannot expand <sfile> in a Vim9 function"));
|
||||||
|
@ -135,6 +135,20 @@ estack_sfile(estack_arg_T which UNUSED)
|
|||||||
return vim_strsave(entry->es_name);
|
return vim_strsave(entry->es_name);
|
||||||
}
|
}
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
|
// expand('<sfile>') 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.
|
// 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:
|
// For a function we compose the call stack, as it was done in the past:
|
||||||
// "function One[123]..Two[456]..Three"
|
// "function One[123]..Two[456]..Three"
|
||||||
|
@ -915,6 +915,14 @@ def Test_expand()
|
|||||||
CheckDefAndScriptFailure2(['expand("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
|
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')
|
CheckDefAndScriptFailure2(['expand("a", true, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
|
||||||
expand('')->assert_equal('')
|
expand('')->assert_equal('')
|
||||||
|
|
||||||
|
var caught = false
|
||||||
|
try
|
||||||
|
echo expand("<sfile>")
|
||||||
|
catch /E1245:/
|
||||||
|
caught = true
|
||||||
|
endtry
|
||||||
|
assert_true(caught)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expandcmd()
|
def Test_expandcmd()
|
||||||
|
@ -757,6 +757,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 */
|
||||||
|
/**/
|
||||||
|
3646,
|
||||||
/**/
|
/**/
|
||||||
3645,
|
3645,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user