To: vim_dev@googlegroups.com Subject: Patch 8.2.1223 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1223 Problem: Vim9: invalid type error for function default value. Solution: Use right argument index. (closes #6458) Files: src/vim9compile.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1222/src/vim9compile.c 2020-07-15 14:15:47.414627529 +0200 --- src/vim9compile.c 2020-07-15 19:44:41.673273675 +0200 *************** *** 6865,6871 **** val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; if (ufunc->uf_arg_types[arg_idx] == &t_unknown) ufunc->uf_arg_types[arg_idx] = val_type; ! else if (check_type(ufunc->uf_arg_types[i], val_type, FALSE) == FAIL) { arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type, --- 6865,6871 ---- val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; if (ufunc->uf_arg_types[arg_idx] == &t_unknown) ufunc->uf_arg_types[arg_idx] = val_type; ! else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, FALSE) == FAIL) { arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type, *** ../vim-8.2.1222/src/testdir/test_vim9_func.vim 2020-07-15 14:15:47.418627519 +0200 --- src/testdir/test_vim9_func.vim 2020-07-15 19:43:13.005483540 +0200 *************** *** 104,114 **** --- 104,122 ---- return name enddef + def MyDefaultSecond(name: string, second: bool = true): string + return second ? name : 'none' + enddef + def Test_call_default_args() assert_equal('string', MyDefaultArgs()) assert_equal('one', MyDefaultArgs('one')) assert_fails('call MyDefaultArgs("one", "two")', 'E118:') + assert_equal('test', MyDefaultSecond('test')) + assert_equal('test', MyDefaultSecond('test', true)) + assert_equal('none', MyDefaultSecond('test', false)) + CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:') CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: argument 1: type mismatch, expected number but got string') enddef *** ../vim-8.2.1222/src/version.c 2020-07-15 18:29:15.072357704 +0200 --- src/version.c 2020-07-15 19:38:52.814081200 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1223, /**/ -- `The Guide says there is an art to flying,' said Ford, `or at least a knack. The knack lies in learning how to throw yourself at the ground and miss.' He smiled weakly. -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///