comparison src/testdir/test_vim9_assign.vim @ 23448:8f31b990ab1e v8.2.2267

patch 8.2.2267: Vim9: cannot use unlet for a dict member Commit: https://github.com/vim/vim/commit/c368957b1904bfaa2b0b52bbcade51b20173f3ed Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 1 19:40:02 2021 +0100 patch 8.2.2267: Vim9: cannot use unlet for a dict member Problem: Vim9: cannot use unlet for a dict member. Solution: Pass GLV_NO_DECL to get_lval(). (closes https://github.com/vim/vim/issues/7585)
author Bram Moolenaar <Bram@vim.org>
date Fri, 01 Jan 2021 19:45:03 +0100
parents 5807e3958e38
children a8e7acf71fa4
comparison
equal deleted inserted replaced
23447:15d05ad7a3a5 23448:8f31b990ab1e
982 CheckDefFailure(["var l: list<number> = ['', true]"], 'E1012: Type mismatch; expected list<number> but got list<any>', 1) 982 CheckDefFailure(["var l: list<number> = ['', true]"], 'E1012: Type mismatch; expected list<number> but got list<any>', 1)
983 CheckDefFailure(["var l: list<list<number>> = [['', true]]"], 'E1012: Type mismatch; expected list<list<number>> but got list<list<any>>', 1) 983 CheckDefFailure(["var l: list<list<number>> = [['', true]]"], 'E1012: Type mismatch; expected list<list<number>> but got list<list<any>>', 1)
984 enddef 984 enddef
985 985
986 def Test_assign_dict() 986 def Test_assign_dict()
987 var d: dict<string> = {} 987 var lines =<< trim END
988 d['key'] = 'value' 988 var d: dict<string> = {}
989 assert_equal('value', d['key']) 989 d['key'] = 'value'
990 990 assert_equal('value', d['key'])
991 d[123] = 'qwerty' 991
992 assert_equal('qwerty', d[123]) 992 d[123] = 'qwerty'
993 assert_equal('qwerty', d['123']) 993 assert_equal('qwerty', d[123])
994 994 assert_equal('qwerty', d['123'])
995 var nrd: dict<number> = {} 995
996 for i in range(3) 996 var nrd: dict<number> = {}
997 nrd[i] = i 997 for i in range(3)
998 endfor 998 nrd[i] = i
999 assert_equal({0: 0, 1: 1, 2: 2}, nrd) 999 endfor
1000 assert_equal({0: 0, 1: 1, 2: 2}, nrd)
1001
1002 d.somekey = 'someval'
1003 assert_equal({key: 'value', '123': 'qwerty', somekey: 'someval'}, d)
1004 # unlet d.somekey
1005 # assert_equal({key: 'value', '123': 'qwerty'}, d)
1006 END
1007 CheckDefAndScriptSuccess(lines)
1008
1009 # TODO: move to above once "unlet d.somekey" in :def is implemented
1010 lines =<< trim END
1011 vim9script
1012 var d: dict<string> = {}
1013 d['key'] = 'value'
1014 d.somekey = 'someval'
1015 assert_equal({key: 'value', somekey: 'someval'}, d)
1016 unlet d.somekey
1017 assert_equal({key: 'value'}, d)
1018 END
1019 CheckScriptSuccess(lines)
1000 1020
1001 CheckDefFailure(["var d: dict<number> = {a: '', b: true}"], 'E1012: Type mismatch; expected dict<number> but got dict<any>', 1) 1021 CheckDefFailure(["var d: dict<number> = {a: '', b: true}"], 'E1012: Type mismatch; expected dict<number> but got dict<any>', 1)
1002 CheckDefFailure(["var d: dict<dict<number>> = {x: {a: '', b: true}}"], 'E1012: Type mismatch; expected dict<dict<number>> but got dict<dict<any>>', 1) 1022 CheckDefFailure(["var d: dict<dict<number>> = {x: {a: '', b: true}}"], 'E1012: Type mismatch; expected dict<dict<number>> but got dict<dict<any>>', 1)
1003 enddef 1023 enddef
1004 1024