Patch 8.2.2099
Problem:    Vim9: some checks are not tested.
Solution:   Add a few more tests.  Give better error messages.
Files:      src/vim9compile.c, src/testdir/test_vim9_script.vim,
            src/testdir/test_vim9_expr.vim


*** ../vim-8.2.2098/src/vim9compile.c   2020-12-05 19:17:12.603703388 +0100
--- src/vim9compile.c   2020-12-06 14:31:24.865907914 +0100
***************
*** 2503,2509 ****
                case 'w': isn_type = ISN_LOADW; break;
                case 't': isn_type = ISN_LOADT; break;
                case 'b': isn_type = ISN_LOADB; break;
!               default:  semsg(_(e_namespace_not_supported_str), *arg);
                          goto theend;
            }
            if (isn_type != ISN_DROP)
--- 2503,2510 ----
                case 'w': isn_type = ISN_LOADW; break;
                case 't': isn_type = ISN_LOADT; break;
                case 'b': isn_type = ISN_LOADB; break;
!               default:  // cannot happen, just in case
!                         semsg(_(e_namespace_not_supported_str), *arg);
                          goto theend;
            }
            if (isn_type != ISN_DROP)
***************
*** 3581,3587 ****
                else
                {
                    if (compile_expr0(arg, cctx) == FAIL)
!                   return FAIL;
                    if (may_get_next_line_error(p, arg, cctx) == FAIL)
                        return FAIL;
                    *arg = skipwhite(*arg);
--- 3582,3588 ----
                else
                {
                    if (compile_expr0(arg, cctx) == FAIL)
!                       return FAIL;
                    if (may_get_next_line_error(p, arg, cctx) == FAIL)
                        return FAIL;
                    *arg = skipwhite(*arg);
***************
*** 4084,4090 ****
            return FAIL;
        }
        *arg = skipwhite(op + 1);
!       if (may_get_next_line(op + 1, arg, cctx) == FAIL)
            return FAIL;
  
        // get the second expression
--- 4085,4091 ----
            return FAIL;
        }
        *arg = skipwhite(op + 1);
!       if (may_get_next_line_error(op + 1, arg, cctx) == FAIL)
            return FAIL;
  
        // get the second expression
***************
*** 4291,4297 ****
  
        // get the second variable
        *arg = skipwhite(p + len);
!       if (may_get_next_line(p + len, arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr5(arg, cctx, ppconst) == FAIL)
--- 4292,4298 ----
  
        // get the second variable
        *arg = skipwhite(p + len);
!       if (may_get_next_line_error(p + len, arg, cctx) == FAIL)
            return FAIL;
  
        if (compile_expr5(arg, cctx, ppconst) == FAIL)
***************
*** 4390,4396 ****
  
            // eval the next expression
            *arg = skipwhite(p + 2);
!           if (may_get_next_line(p + 2, arg, cctx) == FAIL)
                return FAIL;
  
            if ((opchar == '|' ? compile_expr3(arg, cctx, ppconst)
--- 4391,4397 ----
  
            // eval the next expression
            *arg = skipwhite(p + 2);
!           if (may_get_next_line_error(p + 2, arg, cctx) == FAIL)
                return FAIL;
  
            if ((opchar == '|' ? compile_expr3(arg, cctx, ppconst)
***************
*** 4584,4590 ****
  
        // evaluate the second expression; any type is accepted
        *arg = skipwhite(p + 1 + op_falsy);
!       if (may_get_next_line(p + 1 + op_falsy, arg, cctx) == FAIL)
            return FAIL;
        if (compile_expr1(arg, cctx, ppconst) == FAIL)
            return FAIL;
--- 4585,4591 ----
  
        // evaluate the second expression; any type is accepted
        *arg = skipwhite(p + 1 + op_falsy);
!       if (may_get_next_line_error(p + 1 + op_falsy, arg, cctx) == FAIL)
            return FAIL;
        if (compile_expr1(arg, cctx, ppconst) == FAIL)
            return FAIL;
***************
*** 4634,4640 ****
                cctx->ctx_skip = save_skip == SKIP_YES || const_value
                                                         ? SKIP_YES : SKIP_NOT;
            *arg = skipwhite(p + 1);
!           if (may_get_next_line(p + 1, arg, cctx) == FAIL)
                return FAIL;
            if (compile_expr1(arg, cctx, ppconst) == FAIL)
                return FAIL;
--- 4635,4641 ----
                cctx->ctx_skip = save_skip == SKIP_YES || const_value
                                                         ? SKIP_YES : SKIP_NOT;
            *arg = skipwhite(p + 1);
!           if (may_get_next_line_error(p + 1, arg, cctx) == FAIL)
                return FAIL;
            if (compile_expr1(arg, cctx, ppconst) == FAIL)
                return FAIL;
*** ../vim-8.2.2098/src/testdir/test_vim9_script.vim    2020-12-05 
13:40:57.499035073 +0100
--- src/testdir/test_vim9_script.vim    2020-12-06 13:39:55.971822771 +0100
***************
*** 962,967 ****
--- 962,979 ----
    writefile(import_already_defined, 'Ximport.vim')
    assert_fails('source Ximport.vim', 'E1073:', '', 3, 'Ximport.vim')
  
+   # try changing an imported const
+   var import_assign_to_const =<< trim END
+     vim9script
+     import CONST from './Xexport.vim'
+     def Assign()
+       CONST = 987
+     enddef
+     defcompile
+   END
+   writefile(import_assign_to_const, 'Ximport.vim')
+   assert_fails('source Ximport.vim', 'E46:', '', 1, '_Assign')
+ 
    # import a very long name, requires making a copy
    var import_long_name_lines =<< trim END
      vim9script
*** ../vim-8.2.2098/src/testdir/test_vim9_expr.vim      2020-12-04 
19:11:53.881306962 +0100
--- src/testdir/test_vim9_expr.vim      2020-12-06 14:33:42.985439618 +0100
***************
*** 188,193 ****
--- 188,199 ----
    call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1)
    call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1)
  
+   call CheckDefExecFailure(["var x = false ? "], 'E1097:', 2)
+   call CheckDefExecFailure(["var x = false ? 'one' : "], 'E1097:', 2)
+ 
+   call CheckDefExecFailure(["var x = true ? xxx : 'foo'"], 'E1001:', 1)
+   call CheckDefExecFailure(["var x = false ? 'foo' : xxx"], 'E1001:', 1)
+ 
    if has('float')
      call CheckDefFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1)
    endif
***************
*** 346,351 ****
--- 352,359 ----
    call CheckDefFailure(["var x = 1 ||2"], msg, 1)
    call CheckDefFailure(["var x = 1|| 2"], msg, 1)
  
+   call CheckDefFailure(["var x = false || "], 'E1097:', 2)
+ 
    call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1)
    call CheckDefFailure(["var x = [] || false"], 'E1012:', 1)
    call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type 
mismatch; expected bool but got string', 1)
***************
*** 579,584 ****
--- 587,594 ----
    CheckDefAndScriptSuccess(lines)
  
    CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1)
+   CheckDefFailure(["var x = 'a' == "], 'E1097:', 2)
+ 
    CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == 
[]', 'endif'], 'E691:', 4)
  enddef
  
***************
*** 1349,1354 ****
--- 1359,1365 ----
    CheckDefAndScriptSuccess(lines)
  
    CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1)
+   CheckDefFailure(["var d = 6 * "], 'E1097:', 2)
  enddef
  
  def Test_expr6_vim9script()
***************
*** 1520,1525 ****
--- 1531,1537 ----
    assert_equal(234, nr)
  
    CheckDefFailure(["var x = <nr>123"], 'E1010:', 1)
+   CheckDefFailure(["var x = <number>"], 'E1097:', 2)
    CheckDefFailure(["var x = <number >123"], 'E1068:', 1)
    CheckDefFailure(["var x = <number 123"], 'E1104:', 1)
  enddef
***************
*** 2053,2058 ****
--- 2065,2097 ----
    CheckScriptFailure(lines, 'E1012:', 2)
  
    lines =<< trim END
+     vim9script
+     var d = {['a']: 234, ['b': 'x'}
+   END
+   CheckScriptFailure(lines, 'E1139:', 2)
+   lines =<< trim END
+     vim9script
+     def Func()
+       var d = {['a']: 234, ['b': 'x'}
+     enddef
+     defcompile
+   END
+   CheckScriptFailure(lines, 'E1139:', 1)
+   lines =<< trim END
+     vim9script
+     var d = {'a':
+   END
+   CheckScriptFailure(lines, 'E15:', 2)
+   lines =<< trim END
+     vim9script
+     def Func()
+       var d = {'a':
+     enddef
+     defcompile
+   END
+   CheckScriptFailure(lines, 'E723:', 1)
+ 
+   lines =<< trim END
        vim9script
        def Failing()
          job_stop()
***************
*** 2566,2571 ****
--- 2605,2643 ----
    END
    CheckDefSuccess(lines)
    CheckScriptSuccess(['vim9script'] + lines)
+ 
+   lines =<< trim END
+       var d = 'asdf'[1:
+   END
+   CheckDefFailure(lines, 'E1097:', 2)
+   lines =<< trim END
+       var d = 'asdf'[1:xxx]
+   END
+   CheckDefFailure(lines, 'E1001:', 1)
+   lines =<< trim END
+       var d = 'asdf'[1:2
+   END
+   CheckDefFailure(lines, 'E1097:', 2)
+   lines =<< trim END
+       var d = 'asdf'[1:2
+       echo d
+   END
+   CheckDefFailure(lines, 'E111:', 2)
+   lines =<< trim END
+       var d = 'asdf'['1']
+       echo d
+   END
+   CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got 
string', 1)
+   lines =<< trim END
+       var d = 'asdf'['1':2]
+       echo d
+   END
+   CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got 
string', 1)
+   lines =<< trim END
+       var d = 'asdf'[1:'2']
+       echo d
+   END
+   CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got 
string', 1)
  enddef
  
  def Test_expr7_list_subscript()
*** ../vim-8.2.2098/src/version.c       2020-12-05 21:46:50.154387600 +0100
--- src/version.c       2020-12-06 13:40:49.295656499 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2099,
  /**/

-- 
   Arthur pulls Pin out.  The MONK blesses the grenade as ...
ARTHUR:  (quietly) One, two, five ...
GALAHAD: Three, sir!
ARTHUR:  Three.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012061337.0B6DbZec1083199%40masaka.moolenaar.net.

Raspunde prin e-mail lui