Skip to content

Commit 81530e3

Browse files
committed
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Problem: Vim9: no error using heredoc for a number variable. Solution: Add a type check. (closes #8627)
1 parent d47c397 commit 81530e3

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/evalvars.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ ex_let(exarg_T *eap)
817817
else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<')
818818
{
819819
list_T *l;
820+
long cur_lnum = SOURCING_LNUM;
820821

821822
// HERE document
822823
l = heredoc_get(eap, expr + 3, FALSE);
@@ -825,6 +826,8 @@ ex_let(exarg_T *eap)
825826
rettv_list_set(&rettv, l);
826827
if (!eap->skip)
827828
{
829+
// errors are for the assignment, not the end marker
830+
SOURCING_LNUM = cur_lnum;
828831
op[0] = '=';
829832
op[1] = NUL;
830833
(void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count,

src/testdir/test_vim9_assign.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,14 @@ def Test_heredoc()
13921392
[END]
13931393
CheckScriptFailure(lines, 'E1145: Missing heredoc end marker: END')
13941394
delfunc! g:Func
1395+
1396+
lines =<< trim END
1397+
var lines: number =<< trim STOP
1398+
aaa
1399+
bbb
1400+
STOP
1401+
END
1402+
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<string>', 1)
13951403
enddef
13961404

13971405
def Test_var_func_call()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3239,
758760
/**/
759761
3238,
760762
/**/

src/vim9compile.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6875,7 +6875,15 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
68756875
if (compile_assign_lhs(var_start, &lhs, cmdidx,
68766876
is_decl, heredoc, oplen, cctx) == FAIL)
68776877
goto theend;
6878-
if (!heredoc)
6878+
if (heredoc)
6879+
{
6880+
SOURCING_LNUM = start_lnum;
6881+
if (lhs.lhs_has_type
6882+
&& need_type(&t_list_string, lhs.lhs_type,
6883+
-1, 0, cctx, FALSE, FALSE) == FAIL)
6884+
goto theend;
6885+
}
6886+
else
68796887
{
68806888
if (cctx->ctx_skip == SKIP_YES)
68816889
{

0 commit comments

Comments
 (0)