summaryrefslogtreecommitdiff
path: root/src/scriptfile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-11-22 15:37:15 +0000
committerBram Moolenaar <Bram@vim.org>2021-11-22 15:37:15 +0000
commitc449271f4efa44725c40116a95b213813040312f (patch)
treef495ca9513d62700fe76e1d526565e899e4688da /src/scriptfile.c
parent7d5b8becc342e49e491053ea842e59f82d072001 (diff)
downloadvim-git-c449271f4efa44725c40116a95b213813040312f.tar.gz
patch 8.2.3646: using <sfile> in a function gives an unexpected resultv8.2.3646
Problem: Using <sfile> in a function gives an unexpected result. Solution: Give an error in a Vim9 function. (issue #9189)
Diffstat (limited to 'src/scriptfile.c')
-rw-r--r--src/scriptfile.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/scriptfile.c b/src/scriptfile.c
index 587aa29a0..7ff9672f2 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -135,6 +135,20 @@ estack_sfile(estack_arg_T which UNUSED)
return vim_strsave(entry->es_name);
}
#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.
// For a function we compose the call stack, as it was done in the past:
// "function One[123]..Two[456]..Three"