Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 20355:fc2d76e0994c v8.2.0733
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Commit: https://github.com/vim/vim/commit/cb2bdb1c6d8b6df4a3d9cfb1ad9e602dace5d310
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 10 22:53:56 2020 +0200
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Problem: Vim9: assigning to dict or list argument does not work.
Solution: Recognize an argument as assignment target.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 10 May 2020 23:00:04 +0200 |
parents | 98e7b880b7b1 |
children | 5950284a517f |
comparison
equal
deleted
inserted
replaced
20354:6f2382829d91 | 20355:fc2d76e0994c |
---|---|
189 | 189 |
190 def Test_using_var_as_arg() | 190 def Test_using_var_as_arg() |
191 call writefile(['def Func(x: number)', 'let x = 234', 'enddef'], 'Xdef') | 191 call writefile(['def Func(x: number)', 'let x = 234', 'enddef'], 'Xdef') |
192 call assert_fails('so Xdef', 'E1006:') | 192 call assert_fails('so Xdef', 'E1006:') |
193 call delete('Xdef') | 193 call delete('Xdef') |
194 enddef | |
195 | |
196 def DictArg(arg: dict<string>) | |
197 arg['key'] = 'value' | |
198 enddef | |
199 | |
200 def ListArg(arg: list<string>) | |
201 arg[0] = 'value' | |
202 enddef | |
203 | |
204 def Test_assign_to_argument() | |
205 " works for dict and list | |
206 let d: dict<string> = {} | |
207 DictArg(d) | |
208 assert_equal('value', d['key']) | |
209 let l: list<string> = [] | |
210 ListArg(l) | |
211 assert_equal('value', l[0]) | |
212 | |
213 call CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef'], 'E1090:') | |
194 enddef | 214 enddef |
195 | 215 |
196 def Test_call_func_defined_later() | 216 def Test_call_func_defined_later() |
197 call assert_equal('one', g:DefinedLater('one')) | 217 call assert_equal('one', g:DefinedLater('one')) |
198 call assert_fails('call NotDefined("one")', 'E117:') | 218 call assert_fails('call NotDefined("one")', 'E117:') |