Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 24272:cabed216cc2f v8.2.2677
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Commit: https://github.com/vim/vim/commit/38a3bfa9a2931729a5e0c28dc087f745b68988ef
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 29 22:14:55 2021 +0200
patch 8.2.2677: Vim9: cannot use only some of the default arguments
Problem: Vim9: cannot use only some of the default arguments.
Solution: Use v:none to use default argument value. Remove
uf_def_arg_idx[], use JUMP_IF_ARG_SET. (closes #6504)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 29 Mar 2021 22:15:03 +0200 |
parents | 40e27d96e395 |
children | beb395ca3e2f |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -308,21 +308,38 @@ def MyDefaultSecond(name: string, second return second ? name : 'none' enddef + def Test_call_default_args() MyDefaultArgs()->assert_equal('string') + MyDefaultArgs(v:none)->assert_equal('string') MyDefaultArgs('one')->assert_equal('one') - assert_fails('MyDefaultArgs("one", "two")', 'E118:', '', 3, 'Test_call_default_args') + assert_fails('MyDefaultArgs("one", "two")', 'E118:', '', 4, 'Test_call_default_args') MyDefaultSecond('test')->assert_equal('test') MyDefaultSecond('test', true)->assert_equal('test') MyDefaultSecond('test', false)->assert_equal('none') + var lines =<< trim END + def MyDefaultThird(name: string, aa = 'aa', bb = 'bb'): string + return name .. aa .. bb + enddef + + MyDefaultThird('->')->assert_equal('->aabb') + MyDefaultThird('->', v:none)->assert_equal('->aabb') + MyDefaultThird('->', 'xx')->assert_equal('->xxbb') + MyDefaultThird('->', v:none, v:none)->assert_equal('->aabb') + MyDefaultThird('->', 'xx', v:none)->assert_equal('->xxbb') + MyDefaultThird('->', v:none, 'yy')->assert_equal('->aayy') + MyDefaultThird('->', 'xx', 'yy')->assert_equal('->xxyy') + END + CheckDefAndScriptSuccess(lines) + CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:') delfunc g:Func CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string') delfunc g:Func - var lines =<< trim END + lines =<< trim END vim9script def Func(a = b == 0 ? 1 : 2, b = 0) enddef