summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorh-east <h.east.727@gmail.com>2023-01-09 15:10:40 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-09 15:10:40 +0000
commit01c5f2addf86b8d8940d71c92f6219f14a6df99e (patch)
tree98f67bece937f75625f0eff0fb40dc04cd8d9fee
parentdda3053121abd72f50788d6615163e99c1cfff2b (diff)
downloadvim-git-01c5f2addf86b8d8940d71c92f6219f14a6df99e.tar.gz
patch 9.0.1164: evaluating string expression advances function linev9.0.1164
Problem: Evaluating string expression advances function line. Solution: Disable function lines while parsing a string expression. (Hirohito Higashi, closes #11796)
-rw-r--r--src/testdir/test_vim9_expr.vim11
-rw-r--r--src/version.c2
-rw-r--r--src/vim9expr.c8
3 files changed, 21 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 63547820c..29a17fe25 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -3700,6 +3700,17 @@ def Test_expr9_method_call_linebreak()
assert_equal('', v:errmsg)
END
v9.CheckScriptSuccess(lines)
+
+ # this was skipping over the expression without an error
+ lines =<< trim END
+ vim9script
+ def Test(s: string): string
+ return substitute(s, 'A', '\=toupper("x")', 'g')
+ ->tolower()
+ enddef
+ assert_equal('xbcd', Test('ABCD'))
+ END
+ v9.CheckScriptSuccess(lines)
enddef
def Test_expr9_method_call_import()
diff --git a/src/version.c b/src/version.c
index 4fbd96de0..1f808f3c6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1164,
+/**/
1163,
/**/
1162,
diff --git a/src/vim9expr.c b/src/vim9expr.c
index 3acb97bef..7f5f4c8b0 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -733,7 +733,15 @@ compile_string(isn_T *isn, cctx_T *cctx, int str_offset)
cctx->ctx_instr.ga_len = 0;
cctx->ctx_instr.ga_maxlen = 0;
cctx->ctx_instr.ga_data = NULL;
+
+ // avoid peeking a next line
+ int galen_save = cctx->ctx_ufunc->uf_lines.ga_len;
+ cctx->ctx_ufunc->uf_lines.ga_len = 0;
+
expr_res = compile_expr0(&s, cctx);
+
+ cctx->ctx_ufunc->uf_lines.ga_len = galen_save;
+
s = skipwhite(s);
trailing_error = *s != NUL;