Mercurial > vim
diff src/testdir/test_vim9_assign.vim @ 26935:ccb9be1cdd71 v8.2.3996
patch 8.2.3996: Vim9: type checking lacks information about declared type
Commit: https://github.com/vim/vim/commit/078a46161e8b1b30bf306d6c1f4f0af7c616a989
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 4 15:17:03 2022 +0000
patch 8.2.3996: Vim9: type checking lacks information about declared type
Problem: Vim9: type checking for list and dict lacks information about
declared type.
Solution: Add dv_decl_type and lv_decl_type. Refactor the type stack to
store two types in each entry.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 04 Jan 2022 16:30:06 +0100 |
parents | 4e77f9961650 |
children | 11ee2667a09a |
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -639,6 +639,23 @@ def Test_extend_list() extend(test_null_list(), ['x']) END CheckScriptFailure(lines, 'E1134:', 2) + + # using global var has no declared type + g:myList = [] + g:myList->extend([1]) + g:myList->extend(['x']) + assert_equal([1, 'x'], g:myList) + unlet g:myList + + # using declared list gives an error + lines =<< trim END + var l: list<number> + g:myList = l + g:myList->extend([1]) + g:myList->extend(['x']) + END + CheckDefExecAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 4) + unlet g:myList enddef def Test_extend_dict() @@ -963,6 +980,23 @@ def Test_assignment_dict() var anyDict: dict<any> = {a: 0} assert_equal({a: 0, b: 'x'}, extend(anyDict, {b: 'x'})) + # using global var, which has no declared type + g:myDict = {} + g:myDict->extend({a: 1}) + g:myDict->extend({b: 'x'}) + assert_equal({a: 1, b: 'x'}, g:myDict) + unlet g:myDict + + # using list with declared type gives an error + lines =<< trim END + var d: dict<number> + g:myDict = d + g:myDict->extend({a: 1}) + g:myDict->extend({b: 'x'}) + END + CheckDefExecAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 4) + unlet g:myDict + # assignment to script-local dict lines =<< trim END vim9script