To: vim_dev@googlegroups.com Subject: Patch 9.0.1138 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1138 Problem: Crash when expecting varargs but it is something else. Solution: Only use the member when the type is a list. (closes #11774) Files: src/vim9type.c, src/vim9instr.c, src/testdir/test_vim9_func.vim *** ../vim-9.0.1137/src/vim9type.c 2022-12-29 20:56:20.025538293 +0000 --- src/vim9type.c 2023-01-03 12:00:35.003883901 +0000 *************** *** 932,939 **** if (varargs && i >= type->tt_argcount - 1) { expected = type->tt_args[type->tt_argcount - 1]; ! if (expected != NULL) expected = expected->tt_member; } else expected = type->tt_args[i]; --- 932,941 ---- if (varargs && i >= type->tt_argcount - 1) { expected = type->tt_args[type->tt_argcount - 1]; ! if (expected != NULL && expected->tt_type == VAR_LIST) expected = expected->tt_member; + if (expected == NULL) + expected = &t_any; } else expected = type->tt_args[i]; *** ../vim-9.0.1137/src/vim9instr.c 2023-01-02 20:32:18.425749782 +0000 --- src/vim9instr.c 2023-01-03 12:00:21.035655696 +0000 *************** *** 1841,1847 **** type_T *expected; if (varargs && i >= type->tt_argcount - 1) ! expected = type->tt_args[type->tt_argcount - 1]->tt_member; else if (i >= type->tt_min_argcount && actual->tt_type == VAR_SPECIAL) expected = &t_any; --- 1841,1853 ---- type_T *expected; if (varargs && i >= type->tt_argcount - 1) ! { ! expected = type->tt_args[type->tt_argcount - 1]; ! if (expected != NULL && expected->tt_type == VAR_LIST) ! expected = expected->tt_member; ! if (expected == NULL) ! expected = &t_any; ! } else if (i >= type->tt_min_argcount && actual->tt_type == VAR_SPECIAL) expected = &t_any; *** ../vim-9.0.1137/src/testdir/test_vim9_func.vim 2023-01-02 13:06:22.825633043 +0000 --- src/testdir/test_vim9_func.vim 2023-01-03 12:04:16.391866740 +0000 *************** *** 1869,1874 **** --- 1869,1888 ---- v9.CheckDefFailure(['g:MyVarargsOnly("one", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number') enddef + def Test_varargs_mismatch() + var lines =<< trim END + vim9script + + def Map(Fn: func(...any): number): number + return Fn('12') + enddef + + var res = Map((v) => str2nr(v)) + assert_equal(12, res) + END + v9.CheckScriptSuccess(lines) + enddef + def Test_using_var_as_arg() var lines =<< trim END def Func(x: number) *** ../vim-9.0.1137/src/version.c 2023-01-03 10:54:03.665703997 +0000 --- src/version.c 2023-01-03 12:04:39.467661163 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1138, /**/ -- People who want to share their religious views with you almost never want you to share yours with them. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///