Mercurial > vim
changeset 23122:60a0221beab0 v8.2.2107
patch 8.2.2107: Vim9: some errors not tested
Commit: https://github.com/vim/vim/commit/8ff16e0183e0b07f34c0db8160cf6a472c427eb8
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 7 21:49:52 2020 +0100
patch 8.2.2107: Vim9: some errors not tested
Problem: Vim9: some errors not tested.
Solution: Add tests. Fix getting the right error.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 07 Dec 2020 22:00:04 +0100 |
parents | baa91af1bc99 |
children | 056a2a041cf2 |
files | src/testdir/test_vim9_assign.vim src/testdir/test_vim9_expr.vim src/version.c src/vim9compile.c |
diffstat | 4 files changed, 56 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -225,6 +225,45 @@ def Test_assignment() END enddef +def Test_assign_unpack() + var lines =<< trim END + var v1: number + var v2: number + [v1, v2] = [1, 2] + assert_equal(1, v1) + assert_equal(2, v2) + END + CheckDefAndScriptSuccess(lines) + + lines =<< trim END + var v1: number + var v2: number + [v1, v2] = + END + CheckDefFailure(lines, 'E1097:', 5) + + lines =<< trim END + var v1: number + var v2: number + [v1, v2] = xxx + END + CheckDefFailure(lines, 'E1001:', 3) + + lines =<< trim END + var v1: number + var v2: number + [v1, v2] = popup_clear() + END + CheckDefFailure(lines, 'E1031:', 3) + + lines =<< trim END + var v1: number + var v2: number + [v1, v2] = '' + END + CheckDefFailure(lines, 'E1012: Type mismatch; expected list<any> but got string', 3) +enddef + def Test_assign_linebreak() var nr: number nr = @@ -237,7 +276,7 @@ def Test_assign_linebreak() assert_equal(12, nr) assert_equal(34, n2) - CheckDefFailure(["var x = #"], 'E1097:', 2) + CheckDefFailure(["var x = #"], 'E1097:', 3) enddef def Test_assign_index()
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -188,8 +188,8 @@ func Test_expr1_trinary_fails() 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 = false ? "], 'E1097:', 3) + call CheckDefExecFailure(["var x = false ? 'one' : "], 'E1097:', 3) call CheckDefExecFailure(["var x = true ? xxx : 'foo'"], 'E1001:', 1) call CheckDefExecFailure(["var x = false ? 'foo' : xxx"], 'E1001:', 1) @@ -352,7 +352,7 @@ def Test_expr2_fails() 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 = false || "], 'E1097:', 3) call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1) call CheckDefFailure(["var x = [] || false"], 'E1012:', 1) @@ -587,7 +587,7 @@ def Test_expr4_equal() CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1) - CheckDefFailure(["var x = 'a' == "], 'E1097:', 2) + CheckDefFailure(["var x = 'a' == "], 'E1097:', 3) CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4) enddef @@ -1359,7 +1359,7 @@ def Test_expr6() CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1) - CheckDefFailure(["var d = 6 * "], 'E1097:', 2) + CheckDefFailure(["var d = 6 * "], 'E1097:', 3) enddef def Test_expr6_vim9script() @@ -1531,7 +1531,7 @@ def Test_expr7t() assert_equal(234, nr) CheckDefFailure(["var x = <nr>123"], 'E1010:', 1) - CheckDefFailure(["var x = <number>"], 'E1097:', 2) + CheckDefFailure(["var x = <number>"], 'E1097:', 3) CheckDefFailure(["var x = <number >123"], 'E1068:', 1) CheckDefFailure(["var x = <number 123"], 'E1104:', 1) enddef @@ -1684,8 +1684,8 @@ def Test_expr7_list() CheckDefExecFailure(["echo 1", "var x = [][0]", "echo 3"], 'E684:', 2) CheckDefExecFailure(["var x = g:list_mixed['xx']"], 'E1012:', 1) - CheckDefFailure(["var x = g:list_mixed["], 'E1097:', 2) - CheckDefFailure(["var x = g:list_mixed[0"], 'E1097:', 2) + CheckDefFailure(["var x = g:list_mixed["], 'E1097:', 3) + CheckDefFailure(["var x = g:list_mixed[0"], 'E1097:', 3) CheckDefExecFailure(["var x = g:list_empty[3]"], 'E684:', 1) CheckDefExecFailure(["var l: list<number> = [234, 'x']"], 'E1012:', 1) CheckDefExecFailure(["var l: list<number> = ['x', 234]"], 'E1012:', 1) @@ -1948,8 +1948,8 @@ def Test_expr7_dict() CheckDefAndScriptSuccess(lines) # legacy syntax doesn't work - CheckDefFailure(["var x = #{key: 8}"], 'E1097:', 2) - CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1097:', 2) + CheckDefFailure(["var x = #{key: 8}"], 'E1097:', 3) + CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1097:', 3) CheckDefFailure(["var x = {a:8}"], 'E1069:', 1) CheckDefFailure(["var x = {a : 8}"], 'E1059:', 1) @@ -2609,7 +2609,7 @@ def Test_expr7_string_subscript() lines =<< trim END var d = 'asdf'[1: END - CheckDefFailure(lines, 'E1097:', 2) + CheckDefFailure(lines, 'E1097:', 3) lines =<< trim END var d = 'asdf'[1:xxx] END @@ -2617,7 +2617,7 @@ def Test_expr7_string_subscript() lines =<< trim END var d = 'asdf'[1:2 END - CheckDefFailure(lines, 'E1097:', 2) + CheckDefFailure(lines, 'E1097:', 3) lines =<< trim END var d = 'asdf'[1:2 echo d
--- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2107, +/**/ 2106, /**/ 2105,
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -2229,6 +2229,7 @@ may_get_next_line_error(char_u *whitep, { if (may_get_next_line(whitep, arg, cctx) == FAIL) { + SOURCING_LNUM = cctx->ctx_lnum + 1; emsg(_(e_line_incomplete)); return FAIL; } @@ -5300,7 +5301,7 @@ compile_assignment(char_u *arg, exarg_T wp = op + oplen; p = skipwhite(wp); - if (may_get_next_line(wp, &p, cctx) == FAIL) + if (may_get_next_line_error(wp, &p, cctx) == FAIL) return FAIL; if (compile_expr0(&p, cctx) == FAIL) return NULL;