comparison src/testdir/test_vim9_assign.vim @ 33899:a9ccbadecda1 v9.0.2155

patch 9.0.2155: Vim9: type not kept when assigning vars Commit: https://github.com/vim/vim/commit/d33518522a84b5625e663c1b608e1c68f9f58003 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Dec 8 21:41:23 2023 +0100 patch 9.0.2155: Vim9: type not kept when assigning vars Problem: Vim9: type not kept when assigning vars Solution: When assigning a List or a Dict value to a variable of type 'any', keep the type closes: #13639 closes: #13646 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Dec 2023 15:16:34 +0100
parents cd7acb9bc4fd
children a259471e74fe
comparison
equal deleted inserted replaced
33898:c30e06a0a180 33899:a9ccbadecda1
3321 defcompile 3321 defcompile
3322 END 3322 END
3323 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<A> but got number', 1) 3323 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<A> but got number', 1)
3324 enddef 3324 enddef
3325 3325
3326 " Test for assigning different types of value to a variable of type "any"
3327 def Test_assign_to_any()
3328 for [typestr, val] in [
3329 ["'bool'", 'true'],
3330 ["'number'", '100'],
3331 ["'float'", '1.1'],
3332 ["'string'", '"abc"'],
3333 ["'blob'", '0z10'],
3334 ["'list<number>'", '[1, 2, 3]'],
3335 ["'dict<number>'", '{a: 1}'],
3336 ]
3337 var lines =<< trim eval END
3338 vim9script
3339 var x: any = {val}
3340 assert_equal({typestr}, typename(x))
3341 x = [{{a: 1}}, {{b: 2}}]
3342 assert_equal('list<dict<number>>', typename(x))
3343 def Foo(xarg: any, s: string)
3344 assert_equal(s, typename(xarg))
3345 enddef
3346 Foo({val}, {typestr})
3347 END
3348 v9.CheckSourceSuccess(lines)
3349 endfor
3350 enddef
3351
3326 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 3352 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker