]> granicus.if.org Git - vim/commitdiff
patch 8.2.1455: Vim9: crash when using typecast before constant v8.2.1455
authorBram Moolenaar <Bram@vim.org>
Fri, 14 Aug 2020 20:44:25 +0000 (22:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 14 Aug 2020 20:44:25 +0000 (22:44 +0200)
Problem:    Vim9: crash when using typecast before constant.
Solution:   Generate constant before checking type.  Add tets.

src/testdir/test_vim9_expr.vim
src/version.c
src/vim9compile.c

index fb07586bc26c7b8e765de8422fe7d9382aa20623..38a332601a38c4c41a3f72ed917c81832e9086c2 100644 (file)
@@ -1324,6 +1324,12 @@ let $TESTVAR = 'testvar'
 def Test_expr7t()
   let ls: list<string> = ['a', <string>g:string_empty]
   let ln: list<number> = [<number>g:anint, <number>g:alsoint]
+  let nr = <number>234
+  assert_equal(234, nr)
+
+  call CheckDefFailure(["let x = <nr>123"], 'E1010:')
+  call CheckDefFailure(["let x = <number >123"], 'E1068:')
+  call CheckDefFailure(["let x = <number 123"], 'E1104:')
 enddef
 
 " test low level expression
index e6d929e1a8005f297e3bb3bfe26cdd65990ce33a..e873a9c07e804b8162fb1d7cd2bbe72d5f6b7073 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1455,
 /**/
     1454,
 /**/
index 5c4547d08da05f380dc84cddae46a6e217ff35c3..920628444ef75dc1d80566568d8e4884591c0c1c 100644 (file)
@@ -3501,11 +3501,12 @@ compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
     if (want_type != NULL)
     {
        garray_T    *stack = &cctx->ctx_type_stack;
-       type_T      *actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
+       type_T      *actual;
 
+       generate_ppconst(cctx, ppconst);
+       actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
        if (check_type(want_type, actual, FALSE) == FAIL)
        {
-           generate_ppconst(cctx, ppconst);
            if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL)
                return FAIL;
        }
@@ -5016,6 +5017,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                goto theend;
            if (*skipwhite(p) != ']')
            {
+               // this should not happen
                emsg(_(e_missbrac));
                goto theend;
            }