Skip to content

Commit 6628b7e

Browse files
committed
patch 8.2.2483: Vim9: type error for misformed expression
Problem: Vim9: type error for misformed expression. Solution: Check for end of command before checking type. (closes #7795)
1 parent a5a1ec1 commit 6628b7e

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,21 @@ def Test_if_elseif_else_fails()
17431743
CheckDefFailure(['endif'], 'E580:')
17441744
CheckDefFailure(['if g:abool', 'elseif xxx'], 'E1001:')
17451745
CheckDefFailure(['if true', 'echo 1'], 'E171:')
1746+
1747+
var lines =<< trim END
1748+
var s = ''
1749+
if s = ''
1750+
endif
1751+
END
1752+
CheckDefFailure(lines, 'E488:')
1753+
1754+
lines =<< trim END
1755+
var s = ''
1756+
if s == ''
1757+
elseif s = ''
1758+
endif
1759+
END
1760+
CheckDefFailure(lines, 'E488:')
17461761
enddef
17471762

17481763
let g:bool_true = v:true
@@ -2200,6 +2215,13 @@ def Test_while_loop_fails()
22002215
CheckDefFailure(['break'], 'E587:')
22012216
CheckDefFailure(['if true', 'break'], 'E587:')
22022217
CheckDefFailure(['while 1', 'echo 3'], 'E170:')
2218+
2219+
var lines =<< trim END
2220+
var s = ''
2221+
while s = ''
2222+
endwhile
2223+
END
2224+
CheckDefFailure(lines, 'E488:')
22032225
enddef
22042226

22052227
def Test_interrupt_loop()

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2483,
753755
/**/
754756
2482,
755757
/**/

src/vim9compile.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6701,6 +6701,11 @@ compile_if(char_u *arg, cctx_T *cctx)
67016701
clear_ppconst(&ppconst);
67026702
return NULL;
67036703
}
6704+
if (!ends_excmd2(arg, skipwhite(p)))
6705+
{
6706+
semsg(_(e_trailing_arg), p);
6707+
return NULL;
6708+
}
67046709
if (cctx->ctx_skip == SKIP_YES)
67056710
clear_ppconst(&ppconst);
67066711
else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
@@ -6825,6 +6830,11 @@ compile_elseif(char_u *arg, cctx_T *cctx)
68256830
return NULL;
68266831
}
68276832
cctx->ctx_skip = save_skip;
6833+
if (!ends_excmd2(arg, skipwhite(p)))
6834+
{
6835+
semsg(_(e_trailing_arg), p);
6836+
return NULL;
6837+
}
68286838
if (scope->se_skip_save == SKIP_YES)
68296839
clear_ppconst(&ppconst);
68306840
else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
@@ -7237,6 +7247,11 @@ compile_while(char_u *arg, cctx_T *cctx)
72377247
// compile "expr"
72387248
if (compile_expr0(&p, cctx) == FAIL)
72397249
return NULL;
7250+
if (!ends_excmd2(arg, skipwhite(p)))
7251+
{
7252+
semsg(_(e_trailing_arg), p);
7253+
return NULL;
7254+
}
72407255

72417256
if (bool_on_stack(cctx) == FAIL)
72427257
return FAIL;

0 commit comments

Comments
 (0)