summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-28 21:25:49 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-28 21:25:49 +0200
commit81530e36033dec2c2cd94af6dd48ceb0389e95a2 (patch)
tree3dc9d5809dcad4596602f26e3a4b66453c089fc1
parentd47c39775b8d381005751b7b20da56412dafb5e4 (diff)
downloadvim-git-81530e36033dec2c2cd94af6dd48ceb0389e95a2.tar.gz
patch 8.2.3239: Vim9: no error using heredoc for a number variablev8.2.3239
Problem: Vim9: no error using heredoc for a number variable. Solution: Add a type check. (closes #8627)
-rw-r--r--src/evalvars.c3
-rw-r--r--src/testdir/test_vim9_assign.vim8
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c10
4 files changed, 22 insertions, 1 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index 534163c54..dc747f717 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -817,6 +817,7 @@ ex_let(exarg_T *eap)
else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<')
{
list_T *l;
+ long cur_lnum = SOURCING_LNUM;
// HERE document
l = heredoc_get(eap, expr + 3, FALSE);
@@ -825,6 +826,8 @@ ex_let(exarg_T *eap)
rettv_list_set(&rettv, l);
if (!eap->skip)
{
+ // errors are for the assignment, not the end marker
+ SOURCING_LNUM = cur_lnum;
op[0] = '=';
op[1] = NUL;
(void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count,
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index 03427c841..b2f8feca5 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -1392,6 +1392,14 @@ def Test_heredoc()
[END]
CheckScriptFailure(lines, 'E1145: Missing heredoc end marker: END')
delfunc! g:Func
+
+ lines =<< trim END
+ var lines: number =<< trim STOP
+ aaa
+ bbb
+ STOP
+ END
+ CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<string>', 1)
enddef
def Test_var_func_call()
diff --git a/src/version.c b/src/version.c
index 6a8f7c8af..b705749aa 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3239,
+/**/
3238,
/**/
3237,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index cb00f0348..c6a2965ea 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -6875,7 +6875,15 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
if (compile_assign_lhs(var_start, &lhs, cmdidx,
is_decl, heredoc, oplen, cctx) == FAIL)
goto theend;
- if (!heredoc)
+ if (heredoc)
+ {
+ SOURCING_LNUM = start_lnum;
+ if (lhs.lhs_has_type
+ && need_type(&t_list_string, lhs.lhs_type,
+ -1, 0, cctx, FALSE, FALSE) == FAIL)
+ goto theend;
+ }
+ else
{
if (cctx->ctx_skip == SKIP_YES)
{