To: vim_dev@googlegroups.com Subject: Patch 8.2.4138 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4138 Problem: Vim9: no error for return with argument when the function does not return anything. Solution: Give an error for the invalid argument. (issue #9497) Files: src/vim9cmds.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.4137/src/vim9cmds.c 2022-01-12 16:18:13.801613093 +0000 --- src/vim9cmds.c 2022-01-18 18:40:16.918034616 +0000 *************** *** 2196,2201 **** --- 2196,2206 ---- if (*p != NUL && *p != '|' && *p != '\n') { + if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID) + { + emsg(_(e_returning_value_in_function_without_return_type)); + return NULL; + } if (legacy) { int save_flags = cmdmod.cmod_flags; *************** *** 2231,2243 **** } else { - if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID - && stack_type->tt_type != VAR_VOID - && stack_type->tt_type != VAR_UNKNOWN) - { - emsg(_(e_returning_value_in_function_without_return_type)); - return NULL; - } if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, 0, cctx, FALSE, FALSE) == FAIL) return NULL; --- 2236,2241 ---- *** ../vim-8.2.4137/src/testdir/test_vim9_func.vim 2022-01-08 15:39:35.414385257 +0000 --- src/testdir/test_vim9_func.vim 2022-01-18 18:44:53.925870638 +0000 *************** *** 341,346 **** --- 341,360 ---- ReturnString()->assert_equal('string') ReturnNumber()->assert_equal(123) assert_fails('ReturnGlobal()', 'E1012: Type mismatch; expected number but got string', '', 1, 'ReturnGlobal') + + var lines =<< trim END + vim9script + + def Msg() + echomsg 'in Msg()...' + enddef + + def Func() + return Msg() + enddef + defcompile + END + CheckScriptFailure(lines, 'E1096:') enddef def Test_check_argument_type() *** ../vim-8.2.4137/src/version.c 2022-01-18 17:43:01.061598437 +0000 --- src/version.c 2022-01-18 18:42:07.873970588 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4138, /**/ -- ARTHUR: I command you as King of the Britons to stand aside! BLACK KNIGHT: I move for no man. The Quest for the Holy Grail (Monty Python) /// 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 ///