comparison src/testdir/test_vim9_assign.vim @ 26925:4e77f9961650 v8.2.3991

patch 8.2.3991: Vim9: error when extending dict<any> Commit: https://github.com/vim/vim/commit/114dbda7858df956161c0adba5d4d8279645ff67 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 3 12:28:03 2022 +0000 patch 8.2.3991: Vim9: error when extending dict<any> Problem: Vim9: error when extending dict<any> with another type that it was initialized with. Solution: Also set the type for dict<any> if the initializer has a more specific type. (closes #9461)
author Bram Moolenaar <Bram@vim.org>
date Mon, 03 Jan 2022 13:30:04 +0100
parents 15913ba6363e
children ccb9be1cdd71
comparison
equal deleted inserted replaced
26924:9a1e933647aa 26925:4e77f9961650
755 CheckDefExecFailure(['var ll = [1, 2, 3]', 'll[-4] = 6'], 'E684:') 755 CheckDefExecFailure(['var ll = [1, 2, 3]', 'll[-4] = 6'], 'E684:')
756 756
757 # type becomes list<any> 757 # type becomes list<any>
758 var somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c'] 758 var somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
759 759
760 # type is list<any> even though initializer is list<number>
761 var anyList: list<any> = [0]
762 assert_equal([0, 'x'], extend(anyList, ['x']))
763
760 var lines =<< trim END 764 var lines =<< trim END
761 var d = {dd: test_null_list()} 765 var d = {dd: test_null_list()}
762 d.dd[0] = 0 766 d.dd[0] = 0
763 END 767 END
764 CheckDefExecFailure(lines, 'E1147:', 2) 768 CheckDefExecFailure(lines, 'E1147:', 2)
952 dd[""] = 6 956 dd[""] = 6
953 assert_equal({['']: 6}, dd) 957 assert_equal({['']: 6}, dd)
954 958
955 # type becomes dict<any> 959 # type becomes dict<any>
956 var somedict = rand() > 0 ? {a: 1, b: 2} : {a: 'a', b: 'b'} 960 var somedict = rand() > 0 ? {a: 1, b: 2} : {a: 'a', b: 'b'}
961
962 # type is dict<any> even though initializer is dict<number>
963 var anyDict: dict<any> = {a: 0}
964 assert_equal({a: 0, b: 'x'}, extend(anyDict, {b: 'x'}))
957 965
958 # assignment to script-local dict 966 # assignment to script-local dict
959 lines =<< trim END 967 lines =<< trim END
960 vim9script 968 vim9script
961 var test: dict<any> = {} 969 var test: dict<any> = {}