Skip to content

Commit d110358

Browse files
committed
patch 8.2.1455: Vim9: crash when using typecast before constant
Problem: Vim9: crash when using typecast before constant. Solution: Generate constant before checking type. Add tets.
1 parent 79e8db9 commit d110358

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,12 @@ let $TESTVAR = 'testvar'
13241324
def Test_expr7t()
13251325
let ls: list<string> = ['a', <string>g:string_empty]
13261326
let ln: list<number> = [<number>g:anint, <number>g:alsoint]
1327+
let nr = <number>234
1328+
assert_equal(234, nr)
1329+
1330+
call CheckDefFailure(["let x = <nr>123"], 'E1010:')
1331+
call CheckDefFailure(["let x = <number >123"], 'E1068:')
1332+
call CheckDefFailure(["let x = <number 123"], 'E1104:')
13271333
enddef
13281334

13291335
" test low level expression

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1455,
757759
/**/
758760
1454,
759761
/**/

src/vim9compile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,11 +3501,12 @@ compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
35013501
if (want_type != NULL)
35023502
{
35033503
garray_T *stack = &cctx->ctx_type_stack;
3504-
type_T *actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
3504+
type_T *actual;
35053505

3506+
generate_ppconst(cctx, ppconst);
3507+
actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
35063508
if (check_type(want_type, actual, FALSE) == FAIL)
35073509
{
3508-
generate_ppconst(cctx, ppconst);
35093510
if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL)
35103511
return FAIL;
35113512
}
@@ -5016,6 +5017,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
50165017
goto theend;
50175018
if (*skipwhite(p) != ']')
50185019
{
5020+
// this should not happen
50195021
emsg(_(e_missbrac));
50205022
goto theend;
50215023
}

0 commit comments

Comments
 (0)