summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-03 21:47:07 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-03 21:47:07 +0200
commita7511c0f4f779140e8b893be506ecffd0ededf04 (patch)
treec6f75bbf2499ee4e27f5c848ce2a7ff0ceac6df2
parent77709b194c71eb02f765521f31b463593bd07cda (diff)
patch 8.2.2706: Vim9: wrong line number reported for boolean operatorv8.2.2706
Problem: Vim9: wrong line number reported for boolean operator. Solution: Use the line number before skipping over line break. (closes #8058)
-rw-r--r--src/testdir/test_vim9_expr.vim30
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c9
3 files changed, 33 insertions, 8 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 7a9b1e49c8..4758feca60 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -467,16 +467,30 @@ def Test_expr3_vimscript()
CheckScriptFailure(lines, 'E1004:', 2)
enddef
-func Test_expr3_fails()
- let msg = "White space required before and after '&&'"
- call CheckDefFailure(["var x = 1&&2"], msg, 1)
- call CheckDefFailure(["var x = 1 &&2"], msg, 1)
- call CheckDefFailure(["var x = 1&& 2"], msg, 1)
+def Test_expr3_fails()
+ var msg = "White space required before and after '&&'"
+ CheckDefFailure(["var x = 1&&2"], msg, 1)
+ CheckDefFailure(["var x = 1 &&2"], msg, 1)
+ CheckDefFailure(["var x = 1&& 2"], msg, 1)
- call CheckDefFailure(["if 'yes' && 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
+ CheckDefFailure(["if 'yes' && 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
- call CheckDefExecFailure(['assert_equal(false, Record(1) && Record(4) && Record(0))'], 'E1023: Using a Number as a Bool: 4', 1)
-endfunc
+ CheckDefExecFailure(['assert_equal(false, Record(1) && Record(4) && Record(0))'], 'E1023: Using a Number as a Bool: 4', 1)
+
+ var lines =<< trim END
+ if 3
+ && true
+ endif
+ END
+ CheckDefExecFailure(lines, 'E1023:', 1)
+
+ lines =<< trim END
+ if 'yes'
+ && true
+ endif
+ END
+ CheckDefFailure(lines, 'E1012:', 1)
+enddef
" global variables to use for tests with the "any" type
let atrue = v:true
diff --git a/src/version.c b/src/version.c
index db8219e5b5..92e3b4c1a8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2706,
+/**/
2705,
/**/
2704,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 4d702d4f9e..d8c955ec57 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4772,6 +4772,10 @@ compile_and_or(
ga_init2(&end_ga, sizeof(int), 10);
while (p[0] == opchar && p[1] == opchar)
{
+ long start_lnum = SOURCING_LNUM;
+ int start_ctx_lnum = cctx->ctx_lnum;
+ int save_lnum;
+
if (next != NULL)
{
*arg = next_line_from_context(cctx, TRUE);
@@ -4790,11 +4794,16 @@ compile_and_or(
generate_ppconst(cctx, ppconst);
// Every part must evaluate to a bool.
+ SOURCING_LNUM = start_lnum;
+ save_lnum = cctx->ctx_lnum;
+ cctx->ctx_lnum = start_ctx_lnum;
if (bool_on_stack(cctx) == FAIL)
{
+ cctx->ctx_lnum = save_lnum;
ga_clear(&end_ga);
return FAIL;
}
+ cctx->ctx_lnum = save_lnum;
if (ga_grow(&end_ga, 1) == FAIL)
{