Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 22236:3d0632b260fd v8.2.1667
patch 8.2.1667: local function name cannot shadow a global function name
Commit: https://github.com/vim/vim/commit/0f769815c82bf93812842e1ad56fcc52c10ff3e5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 12 18:32:34 2020 +0200
patch 8.2.1667: local function name cannot shadow a global function name
Problem: Local function name cannot shadow a global function name.
Solution: Ignore global functions when checking a script-local or scoped
function name. (closes #6926)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Sep 2020 18:45:04 +0200 |
parents | 7b9e8fd7ea5b |
children | e0a4d029cb87 |
comparison
equal
deleted
inserted
replaced
22235:79200ddde036 | 22236:3d0632b260fd |
---|---|
230 s:Funcy() | 230 s:Funcy() |
231 END | 231 END |
232 CheckScriptFailure(lines, 'E117:') | 232 CheckScriptFailure(lines, 'E117:') |
233 enddef | 233 enddef |
234 | 234 |
235 def Test_local_function_shadows_global() | |
236 let lines =<< trim END | |
237 vim9script | |
238 def g:Gfunc(): string | |
239 return 'global' | |
240 enddef | |
241 def AnotherFunc(): number | |
242 let Gfunc = function('len') | |
243 return Gfunc('testing') | |
244 enddef | |
245 g:Gfunc()->assert_equal('global') | |
246 AnotherFunc()->assert_equal(7) | |
247 delfunc g:Gfunc | |
248 END | |
249 CheckScriptSuccess(lines) | |
250 | |
251 lines =<< trim END | |
252 vim9script | |
253 def g:Func(): string | |
254 return 'global' | |
255 enddef | |
256 def AnotherFunc() | |
257 g:Func = function('len') | |
258 enddef | |
259 AnotherFunc() | |
260 END | |
261 CheckScriptFailure(lines, 'E705:') | |
262 delfunc g:Func | |
263 enddef | |
264 | |
235 func TakesOneArg(arg) | 265 func TakesOneArg(arg) |
236 echo a:arg | 266 echo a:arg |
237 endfunc | 267 endfunc |
238 | 268 |
239 def Test_call_wrong_args() | 269 def Test_call_wrong_args() |